Solved

Convert Datetime To UTC

Posted on 2009-07-03
4
555 Views
Last Modified: 2012-05-07
I want to convert an _arbitrary_ smalldatetime into its equivelent UTC.
I do not want to convert the current time to UTC.
(Not wanting to refer to the current time at all, that is why I believe the getUTCDate() function is not applicable.)

So, given: '9/22/2009 1:25:00 PM' I would expect an integer representing the UTC.

Cheers
0
Comment
Question by:silchester
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Rahul Goel ITIL
ID: 24771545
0
 

Author Comment

by:silchester
ID: 24771839
Hi

I have seen this, but the code does not return an integer representing the seconds since the UTC epoch.

still no success unfortunately
0
 
LVL 41

Expert Comment

by:pcelba
ID: 24772066
smalldatetime is counted from 01.01.1900 00:00 and it is rounded to minutes. To call it UTC epoch is not accurate. The number of seconds since smalldatetime beginning will cause numeric overflow when converted to int data type.

You should decide either to convert it to bigint or to calculate number of minutes instead of seconds.
0
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
ID: 24772108
You could maybe look at http://en.wikipedia.org/wiki/Coordinated_Universal_Time and http://en.wikipedia.org/wiki/Unix_time and tell what exactly you need.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

778 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