Solved

Where clause doesn't work on date field

Posted on 2012-03-18
10
534 Views
Last Modified: 2012-03-18
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
0
Comment
Question by:towo2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 13

Expert Comment

by:Ashok
ID: 37734880
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
0
 
LVL 1

Author Comment

by:towo2002
ID: 37734892
Dear Ashok,

Thanks for your quick reply.  Is there anyway to use UK / Australia format?
0
 
LVL 13

Expert Comment

by:Ashok
ID: 37734893
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
0
Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

 
LVL 13

Expert Comment

by:Ashok
ID: 37734900
Is there anyway to use UK / Australia format?

See my post above.

Ashok
0
 
LVL 1

Author Comment

by:towo2002
ID: 37734905
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.
0
 
LVL 13

Accepted Solution

by:
Ashok earned 300 total points
ID: 37734913
If regional setting is DD/MM/YYYY, DateValue function should work.

Try.....(copy & paste from below)

Select * from Q_Analystz_Report where Type = 'C' contract_date > DateValue('01/03/2012')

HTH
Ashok
0
 
LVL 1

Author Comment

by:towo2002
ID: 37734931
Sorry Ashok, one more question.  If I pass this query from VBA / VBScript, I still have to have to use US format?
0
 
LVL 13

Expert Comment

by:Ashok
ID: 37735052
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
0
 
LVL 1

Author Comment

by:towo2002
ID: 37735148
Just did try, have to use US format ;-(
0
 
LVL 13

Expert Comment

by:Ashok
ID: 37735396
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).
0

Featured Post

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question