title: How to store DateTimeOffset in PostreSQL
body: <p>I am having a problem with retrieving a <code>DateTimeOffset</code> from a PostgreSQL database using Entity Framework.  As far as researching the problem, I found <a href="http://www.velir.com/blog/index.php/2012/06/14/timezone-api/" rel="noreferrer">this article</a> that helps me understand what the problem is, but I can't figure out how to fix it.</p>
  
  <p>I have an API that allows users to upload files (mostly images) and it extracts the date that the image was taken and stores it in the database.  It works great most of the time. However, if the date is between March 11 to sometime in April (date varies based on year) before 2007 it saves into the database fine but when trying to retrieve the row, it throws the error:</p>
  
  <blockquote>
    <p>The UTC Offset of the local dateTime parameter does not match the offset argument.</p>
  </blockquote>
  
  <p>I am using the <code>Timestamp With Time Zone</code> type in postgreSQL for the <code>CameraDate</code> field. I can't figure out how to get this to work correctly. If there is a way to do it without changing the database that would be preferable.</p>
  
  <p>Examples:</p>
  
  <pre class="lang-none prettyprint-override"><code>2001-04-01 10:47:17-06 Works
  2001-03-01 10:47:17-06 Works
  2001-03-13 10:47:17-06 Doesn't work
  2007-03-13 10:47:17-06 Works
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>Context.Files.Add(file);
  Context.Entry(file).Reload();
  </code></pre>
  
  <p>File class looks like this (Some fields removed for briefness):</p>
  
  <pre><code>public class File
  {
      [Column("FileId")]
      public override Guid ID { get; set; }
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int DisplayId { get; set; }
      public DateTimeOffset? CameraDate { get; set; }
  }
  </code></pre>