Solved

Where clause doesn't work on date field

Posted on 2012-03-18
10
514 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
  • 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now