JDCam
asked on
SQL 2005 - Current time to GMT
Experts,
I use this code to select the current time. I have been asked to convert it to GMT, so I need to add 4 hours. How can I do this
I use this code to select the current time. I have been asked to convert it to GMT, so I need to add 4 hours. How can I do this
Select
CONVERT(VARCHAR(5),GETDATE(), 108)
As long as Daylight Savings Time is not a problem (and if what you really want is UTC, not GMT), the following may help:
SELECT DATEADD(SECOND,-(DATEDIFF(SECOND,GETDATE(),GETUTCDATE()),GETDATE())
JimHorn solution will work, but only if GMT time is four hours ahead (which can be not always true).
If you want to get the current GMT time, just use the function GETUTCDATE():
Hope this helps. Regards.
If you want to get the current GMT time, just use the function GETUTCDATE():
SELECT GETUTCDATE();
Hope this helps. Regards.
ASKER
all good.. but like my sample I need just the time in 24hr format
Define 'in 24hr format '. This article is a real good cheat sheet for date formats.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
If your question is 'How can I convert any given GETDATE() to GMT', then that will imply some math, as we have to figure out what time zone you're in, plus based on that time zone (and local considerations such as US-Indiana or US-Arizona does not participate in Daylight Savings Time) whether or not you are in DST and therefore need to add/subtract an hour.