dbTalk Databases Forums  

Dates and timezones

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Dates and timezones in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Iain Sharp
 
Posts: n/a

Default Dates and timezones - 05-28-2010 , 10:32 AM






I have an database with many datetime columns in many different
entities.

My application language has theoretically the facility to adjust the
times based on the variation between the client locale and the server
locale, but it's really buggy.

Is there a feature I can use in SQL server 2005 which can apply the
offset during insert update and select based on the database user
log-in? (i.e. so that the dates are stored in GMT but as far as that
database user is concerned they will be in USA(EST)?)

I'm hoping that the application language will fix the bugs, allowing
me to do this in the application, but until then, any ideas?

Iain

Reply With Quote
  #2  
Old   
J M De Moor
 
Posts: n/a

Default Re: Dates and timezones - 05-28-2010 , 01:15 PM






Iain

Quote:
Is there a feature I can use in SQL server 2005 which can apply the
offset during insert update and select based on the database user
log-in? (i.e. so that the dates are stored in GMT but as far as that
database user is concerned they will be in USA(EST)?)

I am not sure I totally understand, but what about:

SELECT DATEDIFF(hh, GetUTCDate(), GETDATE());

Reply With Quote
  #3  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Dates and timezones - 05-28-2010 , 05:21 PM



Iain Sharp (iains (AT) pciltd (DOT) co.uk) writes:
Quote:
I have an database with many datetime columns in many different
entities.

My application language has theoretically the facility to adjust the
times based on the variation between the client locale and the server
locale, but it's really buggy.

Is there a feature I can use in SQL server 2005 which can apply the
offset during insert update and select based on the database user
log-in? (i.e. so that the dates are stored in GMT but as far as that
database user is concerned they will be in USA(EST)?)

I'm hoping that the application language will fix the bugs, allowing
me to do this in the application, but until then, any ideas?
SQL Server has no information about the client's timezone. So if the
client is in New York, and sends in 2010-05-29 13:31 and this is -04:00,
there is no way you can no this in SQL Server with less than passing
the time zone from the client.

If you have the offset, dateadd will help you. But that is also all
you have.

In SQL 2008 there are some new datetime data types, including
datetimeoffset, so that you can store a time-zone value with the
datetime value.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
  #4  
Old   
Iain Sharp
 
Posts: n/a

Default Re: Dates and timezones - 06-01-2010 , 05:31 AM



On Fri, 28 May 2010 23:21:32 +0200, Erland Sommarskog
<esquel (AT) sommarskog (DOT) se> wrote:

Quote:
Iain Sharp (iains (AT) pciltd (DOT) co.uk) writes:
I have an database with many datetime columns in many different
entities.

My application language has theoretically the facility to adjust the
times based on the variation between the client locale and the server
locale, but it's really buggy.

Is there a feature I can use in SQL server 2005 which can apply the
offset during insert update and select based on the database user
log-in? (i.e. so that the dates are stored in GMT but as far as that
database user is concerned they will be in USA(EST)?)

I'm hoping that the application language will fix the bugs, allowing
me to do this in the application, but until then, any ideas?

SQL Server has no information about the client's timezone. So if the
client is in New York, and sends in 2010-05-29 13:31 and this is -04:00,
there is no way you can no this in SQL Server with less than passing
the time zone from the client.

If you have the offset, dateadd will help you. But that is also all
you have.

In SQL 2008 there are some new datetime data types, including
datetimeoffset, so that you can store a time-zone value with the
datetime value.
Yeah, that's mostly what I was afraid of. I was hoping that there was
a timezone offset as an attribute of a database user or something
which would do this for me universally.

I guess I'll just have to store the dates and times as EST until the
application software bugs are ironed out, and then trawl the data
dictionary looking for datetime fields to alter.

Iain

Reply With Quote
  #5  
Old   
Philipp Post
 
Posts: n/a

Default Re: Dates and timezones - 06-01-2010 , 09:25 AM



Quote:
Yeah, that's mostly what I was afraid of. I was hoping that there was a timezone offset as an attribute of a database user or something which would do this for me universally.
If your users do not travel much and you know where they work you
could store the UTC offset in the user profile and use DATEDIFF to
compute the UTC. Downside is that you will have to alter the user
settings based on local summer / winter time rules.

brgds

Philipp Post

Reply With Quote
  #6  
Old   
Iain Sharp
 
Posts: n/a

Default Re: Dates and timezones - 06-02-2010 , 04:03 AM



On Tue, 1 Jun 2010 06:25:03 -0700 (PDT), Philipp Post
<post.philipp (AT) googlemail (DOT) com> wrote:

Quote:
Yeah, that's mostly what I was afraid of. I was hoping that there was a timezone offset as an attribute of a database user or something which would do this for me universally.

If your users do not travel much and you know where they work you
could store the UTC offset in the user profile and use DATEDIFF to
compute the UTC. Downside is that you will have to alter the user
settings based on local summer / winter time rules.

brgds

Philipp Post
Yes I certainly could. If I wasn't waiting for my application
programming language to fix a bug which prevents it from doing exactly
this for me, I probably would. However, there are hundreds of
date-time columns, and I think missing one or two would be worse than
knowing that the dates were all off by the same factor.

If there's no generic 'environment' switch or function for this, then
I have a backup plan, but thanks for your suggestion.

Iain

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.