Solved

convert datetime field to utc format

Posted on 2010-09-16
2
718 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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