Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Date Time Values and Time Zones Expand / Collapse
Author
Message
Posted Friday, December 5, 2003 12:00 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 2:48 AM
Points: 912, Visits: 210
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/dasanka/datetimevaluesandtimezones.asp






My Blog: http://dineshasanka.spaces.live.com/
Post #18919
Posted Monday, December 22, 2003 3:06 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Saturday, February 28, 2009 6:51 AM
Points: 1,489, Visits: 7
Dinesh, please note that GMT and UTC is not exactly the same thing. As I discussed in my article SQL and Java go on a Date (http://www.sqlservercentral.com/columnists/chedgate/sqlandjavagoonadate.asp), UTC adds a "leap second" every year or two. Therefore it is not possible to retrieve the utc-time for a specific datetime using code like this:


DATEADD ( hh , (DATEDIFF ( hh , GetDate(), GetUTCDate() )) , @dt_Date_Time )


The reason is that the difference between getdate and getutcdate will be different depending on when you run it. Of course, if you want the difference in hours (as in your example) you might not notice it because it is only a second every year or two, but there will be a difference. And if you want the difference in milliseconds you would definately note this.

--
Chris Hedgate @ Extralives (http://www.extralives.com/)
Contributor to Best of SQL Server Central 2002 (http://www.sqlservercentral.com/bestof/)
Articles: http://www.sqlservercentral.com/columnists/chedgate/




--
Chris Hedgate http://www.hedgate.net/
Contributor to the Best of SQL Server Central volumes
Articles: http://www.sqlservercentral.com/columnists/chedgate/
Post #90128
Posted Monday, December 22, 2003 3:15 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Saturday, February 28, 2009 6:51 AM
Points: 1,489, Visits: 7
I forgot to mention one thing. The Oracle function SYS_EXTRACT_UTC that you mention is exactly what we would need in SQL Server to solve this problem easily. And from what I understand, this and other time functions will be included in next version of SQL Server.

--
Chris Hedgate @ Extralives (http://www.extralives.com/)
Contributor to Best of SQL Server Central 2002 (http://www.sqlservercentral.com/bestof/)
Articles: http://www.sqlservercentral.com/columnists/chedgate/




--
Chris Hedgate http://www.hedgate.net/
Contributor to the Best of SQL Server Central volumes
Articles: http://www.sqlservercentral.com/columnists/chedgate/
Post #90129
Posted Monday, December 22, 2003 3:29 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 2:48 AM
Points: 912, Visits: 210
Thankx for the information.I didn't notice this
quote:

Dinesh, please note that GMT and UTC is not exactly the same thing. As I discussed in my article SQL and Java go on a Date (http://www.sqlservercentral.com/columnists/chedgate/sqlandjavagoonadate.asp), UTC adds a "leap second" every year or two. Therefore it is not possible to retrieve the utc-time for a specific datetime using code like this:


DATEADD ( hh , (DATEDIFF ( hh , GetDate(), GetUTCDate() )) , @dt_Date_Time )


The reason is that the difference between getdate and getutcdate will be different depending on when you run it. Of course, if you want the difference in hours (as in your example) you might not notice it because it is only a second every year or two, but there will be a difference. And if you want the difference in milliseconds you would definately note this.

--
Chris Hedgate @ Extralives (http://www.extralives.com/)
Contributor to Best of SQL Server Central 2002 (http://www.sqlservercentral.com/bestof/)
Articles: http://www.sqlservercentral.com/columnists/chedgate/










My Blog: http://dineshasanka.spaces.live.com/
Post #90130
Posted Monday, December 22, 2003 5:50 AM
SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: Moderators
Last Login: Friday, November 14, 2014 10:06 AM
Points: 8,370, Visits: 745
Besides

DATEADD ( hh , (DATEDIFF ( hh , GetDate(), GetUTCDate() )) , @dt_Date_Time )

will only deal with the current time difference between the values. Consider that Time Zones in many places shift by an 1 hour back and forth for daylight savings and standard if say you run this on Jann 1 for a Jul 1 date you values will be off by an hour (espeically in the US where the change is 1st Sunday in April and Last Sunday in October). I have previously posted code to deal with transfer from GMT to local time for Eastern Time Zone in US to show the ease and complexity of the situation.




Post #90131
Posted Monday, December 22, 2003 7:02 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, December 7, 2010 6:58 AM
Points: 115, Visits: 17
Has anyone found a way to deal with daylight savings time changes?

In the fall, there would be the possilbility of having duplicate times for events that happened an hour apart...and in the spring, there would be a missing hour.

Just wondering...




Post #90132
Posted Monday, December 22, 2003 11:28 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Saturday, February 28, 2009 6:51 AM
Points: 1,489, Visits: 7
I think the best solution would be to save all datetimes in utc-time. Then you could convert to whichever time zone / format you want for presenting it. Unfortunately though SQL Server does not have all the functions that is needed for this, but I am sure Antares has something up his sleeve.

--
Chris Hedgate @ Extralives (http://www.extralives.com/)
Contributor to Best of SQL Server Central 2002 (http://www.sqlservercentral.com/bestof/)
Articles: http://www.sqlservercentral.com/columnists/chedgate/




--
Chris Hedgate http://www.hedgate.net/
Contributor to the Best of SQL Server Central volumes
Articles: http://www.sqlservercentral.com/columnists/chedgate/
Post #90133
Posted Wednesday, December 22, 2004 3:46 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, October 8, 2013 2:59 PM
Points: 383, Visits: 57

I agree that the best solution is to store all datetimes in UTC time and convert to whichever time zone you want for presenting it. As SQL Server 2000 does not have all the necessary functions needed to do this, your developers will have to write additional code for formatting dates and you will also have to know each user's time zone. If developing in Microsoft.NET then the SimpleTimeZone solution developed by Michael Brumm (http://www.michaelbrumm.com/simpletimezone.html) may be of use.

In your example the two countries are in time zones whose offset is hours different to UTC. However, not all time zones are hours different. For example, India is UTC +4.5 hours. So it would be better to compare datetimes in minutes and not hours.

Keith



Keith
Post #152126
Posted Monday, July 4, 2005 7:47 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, September 29, 2014 10:46 AM
Points: 2,734, Visits: 943

4 tips:

1) Note datetime is a float and a hour is a diference by 4.1666666671517305E-2 u can use these values to make the quick calculations from -4.5 hour or +1 hour o 15 minutes! Less  processing at functions is good for tunning.

2) Read a good article about diference in datetimes formats around the world http://www.sqlservercentral.com/columnists/dasanka/globilizationinsqlserver.asp

3) Store all data at the UTC (or UMC) is good. You can also store the one local datetime at another colummn or just the diference with a LOCAL_datetime-UTC_datetime.

4) U can make all at UTC and let the developers concern about show the correct local datetime and datetime format at the user's interface layer. Argue its cheaper to DB maintenace and good for globalization (yeah it´s right!).

 

Jean

Post #196708
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse