EF6 - UTC DateTime


Is there any way to specify Entity Framework to convert all DateTime in UTC (for azure database storage) ?

I would like that my model stay in local date time. I don't want to duplicate model datetime properties to have one in UTC (for EF) and another one in local (for my views, not mapped in EF).

Popular Answer

Take a look at DateTimeOffset introduced in .Net 4.5 - this stores timezone information as the datetimeoffset SQL type (both SQL Server 2008+ and Azure Database Storage).

By using DateTimeOffset, you do not need to worry anywhere near as much about time zones, which should let you still work in local time for your model.

Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why