title: Providing DateTime values in OData
body: <p>I'm currently writing a special client application to allow our unit tests to work with an OData interface using the XML structure for atom feeds.
  All seems to be working properly, but i'm running into trouble when I need to pass a DateTime value as property.</p>
  
  <p>I've written the following code that extracts the DateTime value from the property of the object and stores it in a specific format:</p>
  
  <pre><code>private static void GenerateProperty&lt;T&gt;(StringBuilder xml, T obj, PropertyInfo info)
          {
              // Extract the information about the property if it contains a value.
              if (info.GetValue(obj, null) == null) return;
              string type = info.GetGetMethod().ReturnType.ToString().Split('.').Last();
              string value = info.GetValue(obj, null).ToString();
              if (type == "DateTime")
                  value = ((DateTime)info.GetValue(obj, null)).ToString("yyyy-mm-ddThh:mm:ss");
              if (type == "Boolean") value = value.ToLower();
  
              // Append the property to the generated XML.
              xml.Append(type.ToLower().Equals("string") ? 
                      string.Format("&lt;d:{0}&gt;{1}&lt;/d:{0}&gt;", info.Name, value) : 
                      string.Format("&lt;d:{0} m:type=\"Edm.{1}\"&gt;{2}&lt;/d:{0}&gt;", info.Name, type, value));
          }
  </code></pre>
  
  <p>The code is heavy on reflection, but that's beside the point. The values returned by this code for a DateTime are in the following format: <strong>2011-49-13T11:49:41Z</strong></p>
  
  <p>However, i'm receiving the following error from my OData Service:</p>
  
  <blockquote>
    <p> 
    <code></code>   Error processing request
    stream. Error encountered in converting the value from request payload
    for property 'Created' to type 'System.DateTime', which is the
    property's expected type. See inner exception for more
    detail.   
        The string '2011-49-13T11:49:41Z' is not a valid AllXsd
    value.
        System.FormatException
           at System.Xml.XmlConvert.ToDateTime(String s,
    XmlDateTimeSerializationMode dateTimeOption)&#xD;    at
    System.Data.Services.Parsing.WebConvert.StringToPrimitive(String text,
    Type targetType)&#xD;    at
    System.Data.Services.Serializers.PlainXmlDeserializer.ConvertValuesForXml(Object
    value, String propertyName, Type typeToBeConverted)<br>
     </p>
  </blockquote>
  
  <p>So apparently it doesn't understand the DateTime format, but when I look at the documentation that's posted here: <a href="http://www.odata.org/developers/protocols/overview#AbstractTypeSystem" rel="noreferrer">http://www.odata.org/developers/protocols/overview#AbstractTypeSystem</a></p>
  
  <p>I'd expect it to be valid. Anyone have any experience with this?</p>