title: How to parse EXIF Date Time data
body: <p>I am writing a C# program that extracts the EXIF <code>DateTimeOriginal</code> field from a JPEG file, if that property is in the data, and I need to parse it into a <code>DateTime</code> value.</p>
  
  <p>The code I have is:</p>
  
  <pre><code>BitmapFrame src = decoder.Frames[ 0 ];
  
  if ( src.Metadata != null ) {
      BitmapMetadata metaData = (BitmapMetadata) src.Metadata;
  
      if ( metaData.ContainsQuery( "/app1/{ushort=0}/{ushort=34665}/{ushort=36867}" ) ) {
          object o = metaData.GetQuery( "/app1/{ushort=0}/{ushort=34665}/{ushort=36867}" );
  
          if ( o != null &amp;&amp; o is string ) {
              string originalDate = Convert.ToString( o );
  
              if ( originalDate != null ) {
                  if ( !DateTime.TryParseExact( originalDate.Trim(), "yyyy:MM:dd hh:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out createDate ) ) {
                      // Sets createDate to a default value if the date doesn't parse.
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>However, the format string in the call to <code>TryParseExact</code> doesn't work, as the code executes the code that is replaced with the comment.</p>
  
  <p>What's the right way to write the format string?  The value in the <code>DateTimeOriginal</code> property is formatted as YYYY:MM:DD HH:MM:SS.  It's the colons in between the YYYY, MM, and DD specifiers that are killing me.  Why'd they use colons??</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I tried changing the format specifier string to "yyyy\:MM\dd hh\:mm:\ss" but that didn't work, either.
  </p>