I was parsing a Reddit RSS feed and noticed that the time was in UTC. The server is located in the EST. The server is located in the timezone that is -5hrs from the UTC. How do I convert the UTC timecode to EST?
Note: I also read that UTC doesn’t follow daylight savings time (DST), I’ll figure out whether to adjust the hour difference later on by using date ranges.
Reddit item node in rss feed
<item>
<title>blah blah</title>
<link>http://blah.com</link>
<guid isPermaLink="true">http://www.reddit.com/r/blah/comments/blah</guid>
<pubDate>Sun, 16 Sep 2012 21:39:17 -0700</pubDate>
<description>blah description</description>
</item>
I came up with this so far:
DECLARE @d DATETIMEOFFSET;
SET @d = 'Sep 2012 21:39:17 -07:00'
DECLARE @off datetime
SET @off = SWITCHOFFSET(@d, '-05:00')
DECLARE @dates TABLE (
converteddate DATETIME
);
insert into @dates (converteddate)
Values (@off)
select * from @dates
My example seems to be the answer from what I’ve read. IF you offset the UTC time by the server’s UTC time offset you get the local time of the server. In this particular case, the server is UTC -05:00
In this example the pubDate’s node is:
I parse the Reddit RSS feed and send the pubDate node as text to SQL. I reformatted the pubDate’s string to this:
The stored procedure I came up with: