Click here to Skip to main content
Licence CPOL
First Posted 11 Jul 2006
Views 91,134
Downloads 1,246
Bookmarked 26 times

SQL Server - Convert UTC to Local Time

By | 11 Jul 2006 | Article
Convert UTC to local time
 
Part of The SQL Zone sponsored by
See Also

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. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionSummary of some issues Pinmemberemperorwal4:27 15 Nov '11  
AnswerRe: Summary of some issues PinmemberJoseph Leathlean6:43 13 Mar '12  
GeneralMy vote of 5 Pinmemberseenit15:18 1 Jul '11  
GeneralIndeed great article Pinmemberkishor kurapati22:54 3 Feb '11  
GeneralNorthern vs. Southern Hemisphere PinmemberJack Siedliski12:23 23 Apr '10  
QuestionDoes not work? Pinmemberretro__12:14 3 Mar '10  
AnswerRe: Does not work? Pinmemberretro__12:36 3 Mar '10  
GeneralDaylight saving time change for USA PinmemberRoman Skrabis23:53 16 Dec '09  
GeneralRe: Daylight saving time change for USA PinmemberJosh Warner-Burke8:46 15 Jan '10  
GeneralRe: Daylight saving time change for USA PinmemberAndyTexas6:09 15 Nov '10  
GeneralIssue where SQL Server DateFirst not set to 7 PinmemberTim Friesen5:21 28 Sep '09  
Generalgreat script Pinmembertrance_dude10:24 28 May '09  
Generalgreat PinmemberRa...aj1:11 17 Mar '09  
General"archive file is damaged" error Pinmemberstephen myint17:57 4 Dec '08  
GeneralThanks for solving a problem that should be handled by the DB PinmemberStephen W Giles7:27 17 Oct '08  
GeneralRe: Thanks for solving a problem that should be handled by the DB Pinmemberbuckindb4:34 3 Nov '08  
GeneralRe: Thanks for solving a problem that should be handled by the DB PinmemberStephen W Giles3:05 4 Nov '08  
GeneralRe: Thanks for solving a problem that should be handled by the DB PinmemberTim Friesen3:06 28 Sep '09  
GeneralRe: Thanks for solving a problem that should be handled by the DB PinmemberTim Friesen3:34 28 Sep '09  
GeneralConvert from local to UTC Pinmembertomasz123458:29 26 Oct '07  
GeneralBug in GetDaylightStandardDateTime Pinmemberrwt2sdf54:01 27 Sep '07  
QuestionHi , Some Proble PinmemberRavi KM Mishra18:28 13 Sep '07  
GeneralSmall problem with GetLocalDateTime Pinmemberrockyfan20617:15 7 Dec '06  
GeneralResponse to question about returning local date only PinmemberChris Tillotson10:10 24 Jul '06  
GeneralThis is great!! One question Pinmembermingo33698:25 24 Jul '06  

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
Web01 | 2.5.120517.1 | Last Updated 11 Jul 2006
Article Copyright 2006 by Chris Tillotson
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid