Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing date in Access SQL query

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.

like image 270
roshanK Avatar asked Aug 05 '12 08:08

roshanK


People also ask

How do you write a SQL query to compare dates?

Here we will see, SQL Query to compare two dates. This can be easily done using equals to(=), less than(<), and greater than(>) operators. In SQL, the date value has DATE datatype which accepts date in 'yyyy-mm-dd' format. To compare two dates, we will declare two dates and compare them using the IF-ELSE statement.

How can I compare date and datetime in SQL Server?

Let's stop using DATEDIFF() or CAST() to filter a table on a DATETIME column. To filter a table on a DATETIME column comparing only the date part, use CAST() only around the parameter, and >= and < with the desired date and the day after.


2 Answers

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#;
like image 163
Fionnuala Avatar answered Oct 13 '22 01:10

Fionnuala


try this..

SELECT * FROM BookingMaster where (JourneyDate >= #01/08/2012#) and (JourneyDate < #01/09/2012#);
like image 33
kakarott Avatar answered Oct 13 '22 01:10

kakarott