Click here to Skip to main content
Click here to Skip to main content

SQL Server - Convert UTC to Local Time

By , 11 Jul 2006
 

Introduction

SQL Server does not provide a simple way to convert a UTC datetime value to a local time value. This project includes a table (tbTimeZoneInfo) with data to provide the Time Zone information and two functions to convert a UTC datetime value to any Local Time Zone.

The tbTimeZoneInfo table contains the Time Zone information for all the time zones from the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones. Anyone familiar with the TIME_ZONE_INFORMATION structure will recognize the structure of table tbTimeZoneInfo.

The function named GetLocalDateTime arguments are a TimeZoneID value from tbTimeZoneInfo and a UTC DateTime value. The GetUTCDate() function can be used to obtain the current UTC date.

Values in the tbTimeZoneInfo can be changed as needed. The values that are supplied in the form of SQL insertion scripts may not be up to date. They were obtained from the registry at a point in time and may now be out of date.

Simply read the UTCToLocal_ReadMe.txt file for instructions on creating the objects, inserting data and testing the GetLocalDateTime function.

History

  • 11th July, 2006: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Chris Tillotson
Web Developer
United States United States
Member
Live in Santa Barbara, CA aka "Paradise" with my awesome wife and daughter. Work as a software developer/typist.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5 PinmemberCesar Esquivel19 Apr '13 - 9:45 
QuestionSummary of some issues Pinmemberemperorwal15 Nov '11 - 4:27 
AnswerRe: Summary of some issues PinmemberJoseph Leathlean13 Mar '12 - 6:43 
GeneralMy vote of 5 Pinmemberseenit1 Jul '11 - 15:18 
GeneralIndeed great article Pinmemberkishor kurapati3 Feb '11 - 22:54 
GeneralNorthern vs. Southern Hemisphere PinmemberJack Siedliski23 Apr '10 - 12:23 
QuestionDoes not work? Pinmemberretro__3 Mar '10 - 12:14 
AnswerRe: Does not work? Pinmemberretro__3 Mar '10 - 12:36 
GeneralDaylight saving time change for USA PinmemberRoman Skrabis16 Dec '09 - 23:53 
GeneralRe: Daylight saving time change for USA PinmemberJosh Warner-Burke15 Jan '10 - 8:46 
GeneralRe: Daylight saving time change for USA PinmemberAndyTexas15 Nov '10 - 6:09 
GeneralIssue where SQL Server DateFirst not set to 7 PinmemberTim Friesen28 Sep '09 - 5:21 
Generalgreat script Pinmembertrance_dude28 May '09 - 10:24 
Generalgreat PinmemberRa...aj17 Mar '09 - 1:11 
General"archive file is damaged" error Pinmemberstephen myint4 Dec '08 - 17:57 
GeneralThanks for solving a problem that should be handled by the DB PinmemberStephen W Giles17 Oct '08 - 7:27 
GeneralRe: Thanks for solving a problem that should be handled by the DB Pinmemberbuckindb3 Nov '08 - 4:34 
GeneralRe: Thanks for solving a problem that should be handled by the DB PinmemberStephen W Giles4 Nov '08 - 3:05 
GeneralRe: Thanks for solving a problem that should be handled by the DB PinmemberTim Friesen28 Sep '09 - 3:06 
GeneralRe: Thanks for solving a problem that should be handled by the DB PinmemberTim Friesen28 Sep '09 - 3:34 
GeneralConvert from local to UTC Pinmembertomasz1234526 Oct '07 - 8:29 
GeneralBug in GetDaylightStandardDateTime Pinmemberrwt2sdf527 Sep '07 - 4:01 
QuestionHi , Some Proble PinmemberRavi KM Mishra13 Sep '07 - 18:28 
GeneralSmall problem with GetLocalDateTime Pinmemberrockyfan2067 Dec '06 - 17:15 
GeneralResponse to question about returning local date only PinmemberChris Tillotson24 Jul '06 - 10:10 
GeneralThis is great!! One question Pinmembermingo336924 Jul '06 - 8:25 
GeneralLink to file is broken. PinmemberMarc Leger11 Jul '06 - 16:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 11 Jul 2006
Article Copyright 2006 by Chris Tillotson
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid