Given a date with timezone set, get the timezone offset in hours

Dan Source

There is a table containing datetime with specified timezone, for example 2015-03-29 03:01:00 +02:00. For every record, I need a query to get this +2 as integer.



answered 6 months ago Reid DeWolfe #1

If that's an actual DateTimeOffset column, and not a string, this should work:

SELECT DATEPART(tz, DateTimeOffsetColumn)/60

answered 6 months ago briskovich #2

This would work too :

select convert(int,  replace(right(column_name , 4), ':00', '' ))  [offset] 

Result: 2

comments powered by Disqus