Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Where clause doesn't work on date field

Posted on 2012-03-18
10
Medium Priority
?
542 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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 1200 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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

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 …
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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.

719 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