Link to home
Start Free TrialLog in
Avatar of towo2002
towo2002

asked on

Where clause doesn't work on date field

Dear all experts,  I've a table which contains some a date field, when I run a query it cannot returns the value that I want, is there any thing wrong in my query?

Select * from Q_Analystz_Report where Type = 'C' contract_date > #01/03/2012#

I expect the above query can return the records which is larger than 1 Mar 2012 (record should up to 17 Mar 2012) but only one record returns.

Please note, the field is in DD/MM/YYYY format
Avatar of Ashok
Ashok
Flag of United States of America image

According to Microsoft

http://office.microsoft.com/en-us/access-help/where-clause-HA001231526.aspx

When you specify the criteria argument, date literals must be in U.S. format, even if you are not using the U.S. version of the Microsoft Access database engine. For example, May 10, 1996, is written 10/5/96 in the United Kingdom and 5/10/96 in the United States.

So try.....

Select * from Q_Analystz_Report where Type = 'C' contract_date > #03/01/2012#

HTH
Ashok
Avatar of towo2002
towo2002

ASKER

Dear Ashok,

Thanks for your quick reply.  Is there anyway to use UK / Australia format?
By the way.....

To find records dated May 10, 1996 in a United Kingdom database, you must use the following SQL statement:
SELECT * FROM Orders WHERE ShippedDate = #5/10/96#;

You can also use the DateValue function which is aware of the international settings established by Microsoft Windows®. For example, use this code for the United States:
SELECT * FROM Orders WHERE ShippedDate = DateValue('5/10/96');

And use this code for the United Kingdom:
SELECT * FROM Orders WHERE ShippedDate = DateValue('10/5/96');

HTH
Ashok
Is there anyway to use UK / Australia format?

See my post above.

Ashok
Dear Ashok,

Another question, how to identify the date format (or regional settings) for my access database?  I'm using English Windows 7 and regional settings is English Australia (date format is DD/MM/YYYY)

I'm using Access 2010.
ASKER CERTIFIED SOLUTION
Avatar of Ashok
Ashok
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry Ashok, one more question.  If I pass this query from VBA / VBScript, I still have to have to use US format?
I think you will have to use US format if you use SQL from VBA.
Query to Access is handled by Access Engine no matter how you pass it.

I cannot say it for sure.  Only way to verify how it will behave is to try it from VBA.

HTH
Ashok
Just did try, have to use US format ;-(
US format with # signs.

You can use DateValue function in SELECT statement and you do not have to use US format (you know it by now).