Solved

convert datetime field to utc format

Posted on 2010-09-16
2
714 Views
Last Modified: 2012-05-10

Can anyone show me a function I can use to change the data format of a field to UTC format?
0
Comment
Question by:jorbroni
2 Comments
 
LVL 9

Accepted Solution

by:
valkyrie_nc earned 500 total points
ID: 33693536
T-SQL unfortunately doesn't have a built-in function to do this, since it's tyipcally handled in the logic of the application using the database.  The quickest way I know to convert is to use DATEADD (and be sure to use minutes instead of hours if you are converting from a timezone that has a UTC conversion of x hours + a half.

For CDT:  DATEADD(mm, 300, [date field])

hth

valkyrie_nc
0
 
LVL 1

Author Closing Comment

by:jorbroni
ID: 33696926

Thanks for the suggestion.

I took your advice and created a function to do the calculation:

ALTER FUNCTION [dbo].[udf_UTCdateformat]

(
@date datetime
)
RETURNS datetime
AS
BEGIN

return DATEADD(minute, DATEDIFF(minute, GETUTCDATE(), GETDATE())*-1, @date)

END
1

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question