locked
OData difference between dates in JSON and ATOM RRS feed

  • Question

  • Hi,

    I'm using OData to query some entities that have dates, if I choose the format ATOM, the dates are correct (are the same as the database),
    but when I choose JSON, the dates are like Date(123456789), when I convert that number the dates are 7 hours behind (for example, if the original date is today at 5 in the morning, the date in JSON is yesterday at 10 at night).

    I'm using converter like http://www.timestampconvert.com.

    There is a special treatment for the dates in JSON format?

    Thanks,
    Christian

    Wednesday, December 5, 2012 10:28 PM

Answers

  • Hi,

    If you want the same format of DateTime as ATOM uses in JSON, use the WCF DS 5.0 on the server (so that you get OData V3 support) and add MinDataServiceVersion:3.0; header to your request. Then JSON will use the same format as ATOM for DateTime (and DateTimeOffset).

    Thanks,


    Vitek Karas [MSFT]

    Thursday, December 6, 2012 1:14 PM
    Moderator

All replies

  • Hi,

    If you want the same format of DateTime as ATOM uses in JSON, use the WCF DS 5.0 on the server (so that you get OData V3 support) and add MinDataServiceVersion:3.0; header to your request. Then JSON will use the same format as ATOM for DateTime (and DateTimeOffset).

    Thanks,


    Vitek Karas [MSFT]

    Thursday, December 6, 2012 1:14 PM
    Moderator
  • Hi Vitek,

    I'm using WCF DS 5.0 on the server, I can change MaxProtocolVersion property to V3
    (config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3),
    but how I can add the header MinDataServiceVersion:3.0?

    Thanks,
    Christian

    Thursday, December 6, 2012 3:29 PM
  • Hi,

    MinDataServiceVersion is an HTTP header which the client sends with the request.

    Thanks


    Vitek Karas [MSFT]

    Thursday, December 6, 2012 5:30 PM
    Moderator
  • If you are using 5.0 or above version of the client, you can use SendingRequest2 event to add this header to every request.

    Hope this helps.

    Thanks

    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, December 6, 2012 6:24 PM
    Moderator
  • Hi,

    I'm using datajs as client, so I had to add the header like this:

    request.headers.MinDataServiceVersion = "3.0";

    Also, I had to change the MaxDataServiceVersion to 3.0.

    Thanks,

    Thursday, December 6, 2012 11:03 PM