December 5, 2003 at 12:00 am
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/dasanka/datetimevaluesandtimezones.asp
My Blog:
December 22, 2003 at 3:06 am
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/
December 22, 2003 at 3:15 am
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/
December 22, 2003 at 3:29 am
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:
December 22, 2003 at 5:50 am
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.
December 22, 2003 at 7:02 am
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...
December 22, 2003 at 11:28 am
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/
December 22, 2004 at 3:46 am
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
July 4, 2005 at 7:47 am
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
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply