Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Getting Current Time in Local Time Zone - SQL Server

RSS
Modified on Fri, May 24, 2019, 6:52 AM by Administrator Categorized as SQL Server, SQL Server System Tables

Overview

When running on a SQL Server whose local clock is in UTC, the GETDATE() function returns a value in UTC. This article provides a means to convert that timestamp into whatever timezone is desired. Note that it doesn't handle time zones that are a fractional number of hours offset from UTC, but the query below can easily be adapted to support this scenario.

Sample Code

declare @tzo int

select @tzo = convert(int, substring(current_utc_offset,1,3)) * 60 from sys.time_zone_info where name = 'Eastern Standard Time'

SELECT DT = dateadd(minute, @tzo, GETUTCDATE())

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2019, Patrick Jasinski.