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

Date format not right

Status
Not open for further replies.

JunglesMcBeef

Programmer
Sep 18, 2003
266
G'day,

I've been trying to use DateTime.Now.ToString("d") within # characters to save a date to an Access db with an Update query. Now the problem is, it saves the date to the table in American format, even though it is represented as Australian format in the string. How do i get the date to save in Australian format?
Here is a snippet of the string:
Code:
Chr(35) & DateTime.Now.ToString("d") & Chr(35)
I have only just started noticing the problem because the current date allows this to happen (ie 10/12/2004 is US format of 12/10/2004 in Australian format). I have all my regional settings set to Australian formats, so why is it all of a sudden saving the dates in American format?
 
I think its in your Access database. You are casting your date to a string and forcing pound signs around this. This tells me that you are concatenating this value to an sql statement. By acknolowledging the string looks correct to you after you cast it....it shouldn't be any problem on the VB side.

Now, if I was you, I would think about passin in ISO dates anyways, to avoid confusion in the future.
 
Try this:
Code:
' use invariant culture
Chr(35) & DateTime.Now.ToString("d", CultureInfo.InvariantCulture) & Chr(35)
Using the invariant culture should produce a datetime string that looks like: yyyy-mm-ddThh-nn-ss which should be accepted by the database.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Riverguy, I took your advice and am now using ISO date format, pending the acceptance from users. chiph, like Riverguy said, the date was being passed in through an SQL statement which means the format looked fine until it actually was saved to the db, meaning Access was most likely the source of the problem. Anyway, thanks for the help guys.
 
How does this affect the users? You said pending acceptance from them. You should still be able to use any date format on your screen that you want for the users.
 
Yeah, I know that...I'm being slack, but I'd also like to use the ISO date format alot more, and if my users get used to the format, it benefits everyone. If they don't like the format, I'll just change the way it is displayed. I don't know why I said pending acceptance from them, I like to think out aloud sometimes :)

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top