While working with azure for a while now I encountered a new issue. I previously used the Table storage on Azure Service Manager (ASM), now this article is based on some new issues I had when changing to the Azure Resource Manager (ASR). Also see my other post about Azure Portals.
Using the Azure Storage Tables I always create an entity, some who have a DateTime object. With a new project I wanted to check the DateTime and compare it with the current. Everything is based on my local machine which is running on UTC+01:00. When comparing the current DateTime with the one that was placed with the entity it never seems to get the right results.
entity.datetime = DateTime.Now.AddMinutes(30)
Check: entity.datetime < DateTime.Now
Result: entity.datetime was always less than the current DateTime.Now.
During investigating with the Windows Azure Storage Explorer I found the following. First view of the records show:
When looking at the detail of the record:
As you see the first view the time shows 11:42 while in the detail view it is 13:42.
Why this is?
Azure uses Universal Time.
Why the Overview shows UT and the detail shows your local time zone I don’t know. What I do know is when you retrieve the information from the table storage the DateTime will be 11:42.
Using DateTime inside your code always consider using Universal Time. For when you want to present the time you can convert is to any time zone that is needed.