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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format for date 1

Status
Not open for further replies.

lehuong

Programmer
Sep 2, 2003
98
US
Hi all,
My vb .net code here:

Dim dtmDate As DateTime
dtmDate = DateTime.Now
txtWOSDate.Text = dtmDate.ToString("d")

when I run it,the expected date format is 21/10/03 but it keep giving me the format 21-Oct-03???
Anyone have any idea about this?
Thanks
Howard
 
Try replacing "d" with "{0:dd MMM yyyy}" or "{0:d}"

The 0 is some type of placemarker, generally required.

 
Thanks,
It worked but acctually I have entercount with another problem which is whenever I user this
Dim dtmDate As DateTime
dtmDate = DateTime.Now
txtWOSDate.Text = dtmDate.ToString("{0:dd MMM yyyy}")
I could not save my data to the microsoft sql sever. There is kind of weirds when I comment out them and type in the txtWOSDate field 21/10/03 then i can save my data. :(
Thanks,
Howard
 
PS: moreover, whenever a date data is being retreaved from the database (with the format 21/10/03) and place it into txtWOSDate field then it became 21-Oct-03 which is very enoying when I compare the date in it with the current date using Operator="GreaterThanEqual". I think the txtWOSDate some how changed the format of the date, if it is correct then how can I adjust the format layout of the date?
Howard
 
le: You might post this problem over at the SQL forum, if you think it might be peculiar to SQL formatting.
 
le: Here's a couple of further examples, maybe something here:

Dim dtmDate AS DateTime

dtmDate = DateTime.Now()

'Short Date
Response.Write(dtmDate.ToString("d"))
displays: 2/13/2001

Response.Write(String.Format("Today is {0:D}", DateTime.Now))
displays: Today is Tuesday, February 13, 2003

note the difference between a lower case "d" (short date) and an uppercase "D" (long date)

good luck!
 
lehuong:

#1) the database stores dates as long. but you can modify it's diplay at the table editor :) so each time you pop them out, the same format will be displayed


 
Hi krispradez,
How can I modify it's diplay at the table editor? Do you have any sample code? Yeah I save it in SQL server then when I retrieved it and put it to the data table it become
23-Oct-03 instead of 23/10/10.
Thanks
lehuong
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top