Solved

convert datetime field to utc format

Posted on 2010-09-16
2
705 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now