Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Label wont show correct date format

Status
Not open for further replies.

johnisotank

Technical User
Aug 8, 2008
258
GB
Hi all,

could someone tell me where I am going wrong here...

My database field [creationdate] is stored as 31/12/2008 23:59.

However, my bound label insists on bringing this in simply as 31/12/2008.

How do i format this so it pulls in correctly please..

Thanks
John
 
OK, here's the thing. Your date is not stored as 31/12/2008 23:59. The format for a date is not stored. The date itself is stored. What you are wanting to do is use the same format in your VB app that your database admin tool is using as a display format. It has nothing to do with how the date is stored internally.

Here is one example on how to force the format, regardless of culture info:

Code:
        Dim dt As New DateTime(2008, 12, 31, 23, 59, 59)
        MessageBox.Show(Format(dt, "dd/MM/yyyy HH:mm"))
 
Hi, thanks for the explanation - really appreciate your time.

So would you recommend I set the format of the label when my form loads?

If so, how would I do that?

Thanks again
John
 
You have to set it when you populate the label. If you are doing some form of auto databinding, then you could use a not enabled masked text box, with a date time format. Otherwise you could return the date/time in the format that you want, by getting it from the database as a varchar value, using convert(varchar(25), myDate, 108) or the one you want.

If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top