0

We have an old database which stores date and time as smalldatetime. The date and times are generated by different applications with this code:

Syste.DateTime appointmentDate = System.DateTime.Now;

We want to migrate this database to make it timezone independed. So we decided to use SQL DateTimeOffSet data type because it comes with all what we need. It stores the UTC date and a offset... just perfect.

Unfortunately we have extremely old applications which are based on .Net 2.0. So there is no System.DateTimeOffSet.

What is the best way to develop a timezone awareness application in .Net 2.0?

  1. Store milliseconds since 1970-01-01 as long data type in database and convert it back to System.DateTime in our application? But then we will lose the timezone
  2. Store date and time as smalldatetime in our database but use System.DateTime.UtcNow to generate date and time on client side? But then we will lose the timezone too.

Background for our migration is this question: Azure App Service - DateTime changes during Sync

Any ideas?

OPunktSchmidt
  • 671
  • 1
  • 9
  • 25
  • Please be more specific about what you are trying to accomplish. Note that `DateTimeOffset` does *not* provide awareness of time zone - only of *offset*. See "Time Zone != Offset" in [the timezone tag wiki](https://stackoverflow.com/tags/timezone/info), and [DateTime vs DateTimeOffset](https://stackoverflow.com/questions/4331189/datetime-vs-datetimeoffset) – Matt Johnson-Pint Jul 28 '17 at 16:49
  • I'm looking for the best way to store utc date in a database. But the requirement is that a .net 2.0 application must read the date from the database. I think i can not use the sql datetimeoffset datatype because .net 2.0 has not the equivalent to this. It would be nice to store also the offset (i know not timezone) where the date was taken. So which sql datatype should i use? – OPunktSchmidt Jul 29 '17 at 17:44
  • 1
    You can store a UTC datetime in a SQL `datetime` or `datetime2` column. There's nothing that requires you use a `datetimeoffset` for that. But also note that `DateTimeOffset` was included with the SP1 update for .NET 2.0, so you may just be able to go ahead and use it as you would in a newer application. – Matt Johnson-Pint Aug 01 '17 at 00:15

0 Answers0