Date Format

J

Jologs

Hi:

strSQL = "INSERT INTO tblLog (Username,logDate) VALUES ('" & txtUserName &
"', #" & txtLogDate & "#);"

I used the above code to update my tblLog. my problem is if the date is a
single digit, it inserts the date in reverse order. E.g. 03-Sep-2005, this
will be inserted to my tblLog as 09-Mar-2005. But if the dates are from 11
to 31, it works fine. I used the same format in the txtLogDate and logDate
(mmm-dd-yyyy", "hh:nn:ss ampm)

Thanks in advance.
 
A

Allen Browne

Literal dates in a SQL statement need to be in the mm/dd/yyyy format.

Try:
strSQL = "INSERT INTO tblLog (Username,logDate) VALUES (""" & _
txtUserName & """, " & Format(txtLogDate, "\#mm\/dd\/yyyy\#") & ");"

If the date contains a time component also, in the Format() function use:
"\#mm\/dd\/yyyy hh\:nn\:ss \#"

This article could be particularly helpful since your examples suggest you
live in a d/m/y country:
International Date Formats in Access
at:
http://allenbrowne.com/ser-36.html
The example above is one of 3 cases where Access is likely to misunderstand
your dates.
 
J

Jologs

Thank very much.

--
Allan


Allen Browne said:
Literal dates in a SQL statement need to be in the mm/dd/yyyy format.

Try:
strSQL = "INSERT INTO tblLog (Username,logDate) VALUES (""" & _
txtUserName & """, " & Format(txtLogDate, "\#mm\/dd\/yyyy\#") & ");"

If the date contains a time component also, in the Format() function use:
"\#mm\/dd\/yyyy hh\:nn\:ss \#"

This article could be particularly helpful since your examples suggest you
live in a d/m/y country:
International Date Formats in Access
at:
http://allenbrowne.com/ser-36.html
The example above is one of 3 cases where Access is likely to misunderstand
your dates.
 
Top