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
243 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 250 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 250 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 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