Solved

convert datetime field to utc format

Posted on 2010-09-16
2
720 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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