Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

convert datetime field to utc format

Posted on 2010-09-16
2
Medium Priority
?
725 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
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, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

604 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