Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 datetime uk or usa

Author  Topic 

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2010-09-14 : 05:22:11
Hi,

If a date is stored in the db as 2010-09-19 00:00:00 (yyyy-mm-dd) is it USA? I am confused as to what the zone is of our client.

Thanks

Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-14 : 05:35:43
quote:
Originally posted by collie

Hi,

If a date is stored in the db as 2010-09-19 00:00:00 (yyyy-mm-dd) is it USA? I am confused as to what the zone is of our client.

Thanks

Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.


Do you think USA is a few days in the future?
In Germany we have today 2010-09-14


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2010-09-14 : 05:53:21
What you mean to tell me USA isn't in the future???

So if date is stored as 2010-09-14 it means it's European and if a date is stored in the db as 2010-14-09 it's USA?
From where does the db take its settings?

Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-09-14 : 06:08:32
quote:
Originally posted by collie

If a date is stored in the db as 2010-09-19 00:00:00 (yyyy-mm-dd) is it USA?


A date isn't stored in any given format, its stored in an unambiguous binary representation. ("Number of days since Epoch" type of thing)

If you present SQL with a date in a string formatted as "2010-09-19" then, all other things being equal, it will treat it as y-m-d - in particular because the Y part has a century and is too big to be M or D, and the D is bigger than 12 and the M smaller than 12.

Irrespective of that 9999-99-99 dates are treated as "y-m-d" by default, but there is nothing to say they have to be.

SET DATEFORMAT MYD
SELECT CONVERT(Datetime, '01-02-03')

gives

2002-01-03

The current setting for which is D, M and Y is influenced by the Country and language of the current login, and the settings of the server.

For output you can format the date how you like ... so if you are seeing some data output from the database it doesn't tell you much, except that the client prefers Y-M-D format and is already enjoying the weekend!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-14 : 06:19:50
You can know more anout it when you read this series
http://beyondrelational.com/blogs/madhivanan/archive/2010/05/25/understanding-datetime-column-part-i.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -