title: Storing date/times as UTC in database
body: <p>I am storing date/times in the database as UTC and computing them inside my application back to local time based on the specific timezone. Say for example I have the following date/time:</p>
  
  <p><code>01/04/2010 00:00</code></p>
  
  <p>Say it is for a country e.g. UK which observes DST (Daylight Savings Time) and at this particular time we are in daylight savings. When I convert this date to UTC and store it in the database it is actually stored as:</p>
  
  <p><code>31/03/2010 23:00</code></p>
  
  <p>As the date would be adjusted -1 hours for DST. This works fine when your observing DST at time of submission. However, what happens when the clock is adjusted back? When I pull that date from the database and convert it to local time that particular datetime would be seen as <code>31/03/2010 23:00</code> when in reality it was processed as <code>01/04/2010 00:00</code>.</p>
  
  <p>Correct me if I am wrong but isn't this a bit of a flaw when storing times as UTC?</p>
  
  <p><b>Example of Timezone conversion</b></p>
  
  <p>Basically what I am doing is storing the date/times of when information is being submitted to my system in order to allow users to do a <em>range</em> report. Here is how I am storing the date/times:</p>
  
  <pre><code>public DateTime LocalDateTime(string timeZoneId)
  {
      var tzi = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
      return TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tzi).ToUniversalTime().ToLocalTime(); 
  }
  </code></pre>
  
  <p>Storing as UTC:</p>
  
  <pre><code>var localDateTime = LocalDateTime("AUS Eastern Standard Time");
  WriteToDB(localDateTime.ToUniversalTime());
  </code></pre>