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

date format in vb and access 1

Status
Not open for further replies.

daveask

Programmer
Aug 11, 2004
108
GB
Hi Experts,

My VB code for getting data from Access database:
myDate = Date()
strSQL = "Select * From Table1 Where [Date] = #" & myDate & "#"
Sometimes this got problem because of the date/time format in Access: mm/dd/yyyy or dd/mm/yyyy.
How to make sure the code is always correct no matter what date/time format is in Access?

Thank you in advance.
 
If I remember correctly you must use the standard American date mask of #mm/dd/yyyy##.

Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@earthlink.net
 
The other thing to keep in mind is that you must use the Date/Time data type in your Access field. Otherwise this will not *always* be successful.
 
Daveask
Try:
Code:
myDate = sFormatedDate = Month(date()) & "/" & Day(date()) & "/" & Year(date())
strSQL = "Select * From Table1 Where [Date] = #" & myDate & "#"

Everybody body is somebodys Nutter.
 
You could also use Format$:
Code:
strDate= Format$(myDate, "\#mm\/dd\/yyyy\#")
strSQL = "Select * From Table1 Where [Date] = " & strDate & ""

 
Thanks a lot for all your responses, I will try.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top