2

I'm trying to convert the datetimeOffset stored in SQL Azure to UTC DateTime so that I can perform a proper calculation.

The DateTimeOffset is stored as local NewZealand Time as:

2011-05-31 21:40:00.0000000 +10:00

I need to convert the above values to UTC so that I can perform date time calculation. Is there any way to achieve this using TSQL and Azure SSRS?

Thanks heaps.

Nil Pun
  • 17,035
  • 39
  • 172
  • 294
  • 1
    possible duplicate of [How can I convert a Sql Server 2008 DateTimeOffset to a DateTime](http://stackoverflow.com/questions/4953903/how-can-i-convert-a-sql-server-2008-datetimeoffset-to-a-datetime) – Ed Harper Jun 22 '11 at 11:39

1 Answers1

2

Here's another thread that may give you some ideas: TSQL: How to convert local time to UTC? (SQL Server 2008)

Off the top of my head, if you know the datetime you are working with is from New Zealand, you know what the UTC offset is. It should be based on one of two values (if they have daylight savings).

So do a dateadd with a function call that determines if you are in daylight savings or not. How do you determine if you are in daylight savings for a given date? Good question. Unless there is a .NET function you could turn into a CLR function, I would just create a look up table and a function that tests against that. The function either returns a boolean or the proper offset for New Zealand.

I would save the new derived value into a new column, but I'm not sure what your needs are.

Community
  • 1
  • 1
geoffrobinson
  • 1,580
  • 3
  • 15
  • 23