?
Solved

Is it possible to query database on date field using uk date format or do I use convert?

Posted on 2008-10-24
7
Medium Priority
?
246 Views
Last Modified: 2012-05-05
I would like to be able to write a query using uk date format

select * from xxx where datefield >= '01/04/2008'

also is there a way to get dates returned from query displayed in uk format or
do I have to use convert in select statement?
0
Comment
Question by:deNZity
[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
  • 2
  • 2
7 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 22801497
That query looks fine.  The default display format of the query likely depends on your installation settings and/or query tool configuation. If you want to request a specific format, by all means convert it to a string of the dexired form.  
0
 

Author Comment

by:deNZity
ID: 22801601
Thanks for the reply,
the following query returns 8 rows where it should only return the last 2 rows.

select * from XXXX
where TransactionDate >= '01/08/2008'


2008-02-08 00:00:00.000
2008-02-18 00:00:00.000
2008-03-28 00:00:00.000
2008-04-10 00:00:00.000
2008-05-02 00:00:00.000
2008-07-16 00:00:00.000
2008-08-01 00:00:00.000
2008-08-29 00:00:00.000
0
 

Author Comment

by:deNZity
ID: 22801608
My regional settings are set to english NZ which is the same as English UK
0
 
LVL 22

Accepted Solution

by:
dportas earned 1000 total points
ID: 22802799
Best practice is to use ISO format for date literals. They will work correctly under any regional settings. Use either:

SELECT * FROM xxx WHERE datefield >= '20080801';

or

SELECT * FROM xxx WHERE datefield >= '2008-08-01T00:00:00';

or

SELECT * FROM xxx WHERE datefield >= '2008-08-01T00:00:00.000';

Hard-coding dates in a query is rather unusual though. If you use datetime variables then you won't need to worry about formatting because datetime values don't have any format. It's only in the unusual case where you want to hard-code a date that you should have to resort to the ISO format.


0
 
LVL 42

Assisted Solution

by:dqmq
dqmq earned 1000 total points
ID: 22804673
Under Server Properties, check your Default Language property.  That governs whether dates are interpreted as mdy (what you are getting) or dmy (what you desire).   US English is dmy.  You can present your dates in the mdy form or you can change the date format using "SET DATEFORMAT dmy"
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

752 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