Comparing date in Access SQL query
Asked Answered
A

2

17

I'm having trouble with Access sql query. Im new to this so bieng a rookie its difficult to figure out the syntax. below is my query.

SELECT *
FROM BookingMaster WHERE JourneyDate = #01/08/2012#;

below is the respective table data:

BookingID   BookingDate    JourneyDate   CustomerName   TelephoneNo  Address
5            01-08-2012     01-08-2012         roshan         78889     hjgj    

the above query listed returns 0 results even though data exist for 01/08/2012 journey date.

Can anyone please help me out.

Alar answered 5/8, 2012 at 8:1 Comment(0)
W
23

Unless you are working in a US locale, it is best to use a year, month, day format for dates:

SELECT *
FROM BookingMaster where JourneyDate = #2012/08/01#;
Watchtower answered 5/8, 2012 at 8:4 Comment(2)
if i have to compare..two date..with following format what i have to do..dd/mm/yyyy is there any format function...?Alar
Yes, there is. Format(ADate,"yyyy/mm/dd") for one (there are others) will return a string. It may not be available outside of Access. How you use dates with MS Access depends a lot on where you are working, the query design screen, VBA, outside of Access, etc.Watchtower
W
4

try this..

SELECT * FROM BookingMaster where (JourneyDate >= #01/08/2012#) and (JourneyDate < #01/09/2012#);
Widener answered 5/8, 2012 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.