I have a DateTime column in a database table.
How can I get the equivalent UTC value for this column?
eg something like the DateTime.ToUniversalTime() in C#.
or select DATE_COL1, getutcdate(DATE_COL1) FROM TABLE
nb: The GETUTCDATE() function returns the current utc DATE 8 30680
It depends what you want to do exactly - is the offset from UTC based
on where the server is physically, where the clients are physically, or
something else? I don't believe there's any easy way to do this in
MSSQL, because you need to know the server's location and current UTC
offset, so you would probably need an external program which gets this
information from the operating system. If you want to base the offset
on the clients' location, then things would be more complicated,
especially if you have clients in different time zones.
If the offset is constant, you could put it in a lookup table and
create your own scalar function to modify the date, but then you would
need to handle daylight savings and so on yourself as well. So if the
C# function you mentioned already does what you want, it might be
easiest just to use it in an external program (in SQL 2005 you could
write a C# stored procedure or function to do this).
Simon
PromisedOyster (Pr************@hotmail.com) writes: I have a DateTime column in a database table.
How can I get the equivalent UTC value for this column?
eg something like the DateTime.ToUniversalTime() in C#.
or select DATE_COL1, getutcdate(DATE_COL1) FROM TABLE
nb: The GETUTCDATE() function returns the current utc DATE
Use the dateadd() function. You will have to handle the logic for
the offset to UTC yourself, as SQL Server does not have any time zone
information.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
We do this all the time:
--test method
DECLARE @Date smalldatetime
SET @Date = GETDATE()
SELECT @date, DATEADD(hh, DATEDIFF(hh, GETDATE(), GETUTCDATE()),
@Date), GETUTCDATE()
You could deal with minutes, but since UTC time is a change in hours,
simply your life :)
Stu
Thanks Stu
I worked this out myself and the proc I developed is about the same as
yours. I had to use minutes though to handle Central Australian Time.
Stu wrote: We do this all the time:
--test method DECLARE @Date smalldatetime SET @Date = GETDATE()
SELECT @date, DATEADD(hh, DATEDIFF(hh, GETDATE(), GETUTCDATE()), @Date), GETUTCDATE()
You could deal with minutes, but since UTC time is a change in hours, simply your life :)
Stu
Really? I never knew that. I always thought that the timezones were
shifts in hours; didnot realize they shifted in half hors as well.
That's gotta be a pain for mking long distance calls.
:)
Stu wrote: Really? I never knew that. I always thought that the timezones were shifts in hours; didnot realize they shifted in half hors as well. That's gotta be a pain for mking long distance calls.
:)
Yes, its true.
And to further complicate things, Nepal is GMT+5:45. They just had to
be different from India. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Max M |
last post by:
# -*- coding: latin-1 -*-
"""
I am currently using the datetime package, but I find that the design is
oddly
asymmetric. I would like to know why. Or perhaps I have misunderstood
how it...
|
by: PK9 |
last post by:
I have a string variable that holds the equivalent of a DateTime value. I
pulled this datetime from the database and I want to strip off the time
portion before displaying to the user.
I am...
|
by: Fritz Switzer |
last post by:
I'd like to have a string assigned the value of a
DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM"
format.
For example:
DateTime.Now.AddMinutes(30) returns "00:30"
...
|
by: Andrew S. Giles |
last post by:
Hello,
I am importing a flat text file, and putting it into a datagrid for display
on a form.
Currently the users have their dates and times seperated. I have two
fields, therefore in the...
|
by: Ante Perkovic |
last post by:
Hi,
How to declare datetime object and set it to my birthday, first or
last day of this month or any other date.
I can't find any examples in VS.NET help!
BTW, what is the difference...
|
by: I am Sam |
last post by:
I have created this DateTime object and instanced it I think correctly
DateTime myClubNow1=new...
|
by: Reny J Joseph Thuthikattu |
last post by:
Hi,
I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a
miniute to it.How can i do that?
by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004
12:00 AM'...
|
by: Cor Ligthert |
last post by:
Hello everybody,
Jay and Herfried are telling me every time when I use CDate that using the
datetime.parseexact is always the best way to do String to datetime
conversions. They don't tell why...
|
by: Phil B |
last post by:
I am having a problem with a datetime from a web services provider
The provider is sending the following SOAP response
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope...
|
by: yasirmturk |
last post by:
Standard Date and Time Functions
The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |