Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Tips Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
SQL Scripts & Samples
» Database Forum
» Slideshows
Free Newsletters:

News Via RSS Feed

Database Journal |DBA Support |SQLCourse |SQLCourse2

Featured Database Articles


Posted Jun 4, 2003

Working with SQL Server Date/Time Variables: Part Four - Date Math and Universal Time - Page 3

By Gregory A. Larsen

Universal Time

So what is "Universal Time"? Universal Time is the local time at the Greenwich meridian, which is longitude zero, or more historically called "Greenwich Mean Time". "Universal Time" is most often used to record astronomical and weather phenomena. Most civil usages of "Universal Time" are normally referred to as "Coordinated Universal Time," which is normally abbreviated as UTC. UTC time is five hours ahead of Eastern Standard Time.


SQL Server provides the GETUTCDATE function to get UTC time. The GETUTCDATE function returns a datetime value that represents the current UTC time. The syntax for the GETUTCDATE function is as follows:


The UTC date and time is calculated based on the current time and time zone on the local machine.

If you run the following command on your server, the current UTC date will be displayed.


GETDATE Function

The GETDATE function provides a means to return the local machine time (time for the time zone set on local server) in internal format. The syntax for the GETDATE function is as follows:


The GETDATE function is useful to get the current time so you can use it in your application.

Now it is time to show a practical example of how to use both the GETUTCDATE and the GETDATE functions. Let's use these functions along with the DATEDIFF function to calculate the number of hours between a local SQL Server machine and "Coordinated Universal Time". Here some code that does exactly that:



I hope this article has shed some light on how to use and what you can do with the DATEADD, and DATEDIFF functions. Also, you should now understand what a UTC date is and how the GETUTCDATE can return a UTC date. In addition, you should also understand how the GETDATE function would return the local server time in internal datetime format.

I hope this article and the first three (part 1, part2, and part3) in this series covered most of what you might need to know to work with all of the different aspects of SQL Server dates.

» See All Articles by Columnist Gregory A. Larsen

MS SQL Archives

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM