Welcome‎ > ‎Version 3‎ > ‎Reference Info‎ > ‎

Working With Dates

*note* To minimize any confusion, we recommend using our php and .net sdks when possible.

  • https://github.com/GroupCommerce/sdk.dotnet
  • https://github.com/GroupCommerce/sdk.php

If you would like additional code samples, please let us know and we can assist you any way possible.  apisupport@groupcommerce.com

JSON Date Processing
All dates returned by the system will be in UTC.  They are listed as milliseconds since 1970/01/01.  

As there is no direct support for the javascript Date object in JSON we are using the workaround defined here: http://weblogs.asp.net/bleroy/archive/2008/01/18/dates-and-json.aspx

The following javascript will parse the json syntax correctly.

var offer = { "offerId: 10, "startDate ": new Date(1308069023484)" };
alert(offer.startDate);


However the above will not pass strict json validation.  We run some preprocessing on the json to make it pass json validation. This is a sample of what the date field will look like when it comes down through json.

JSON.html
{
    "offerId":10,
    "startDate":"\/Date(1308069023484)\/"
}


Below are some code snippets for converting our json into a proper Date object for the respective language.

JavaScript
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
    $.get("/json.html", null, function (offerString) {
        offerString = offerString.replace(/"\\\/Date\((\d+)(?:-\d+)?\)\\\/"/g, "new Date($1)")
        var offer = eval('(' + offerString + ')');
       
        alert(offer.startDate);
    });
</script>


.NET
using (var client = new WebClient())
{
    var text = client.DownloadString("http://website.com/json.html");
    var offer = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(text);
    
    Console.WriteLine(offer["startDate"]);
}

.PHP
<?php
    $ch = curl_init('/json.html');
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1) ;
    $result = curl_exec($ch);
    curl_close($ch);
    $obj = json_decode($result);

    foreach($obj as $var => $value) {
        if(gettype($value) == "string" && (preg_match_all("/^\/Date\((\(?[0-9]*)\)\/$/",$value,$matches))) {
            $obj->$var = new DateTime('@'.(int)($matches[1][0]/1000));
        }
    }
    
    print_r($obj->startDate);
?>

Filtering
When attempting to filter by date, there are several supported formats.

20101020                           Find date matching October 20, 2010
20100422-20101020         Find date between April 22, 2010 and October 20, 2010
ALL                                     Find date between January 1, 1970 and January 1, 2038
FUTURE                               Find date between today's date and January 1, 2038
PAST                                   Find date between January 1, 1970 and today's date.
TODAY                                Find date matching today's date.
TOMORROW (or +1D)          Find date between tomorrow's date and the day after.
YESTERDAY (or -1D)           Find date between day before yesterday and yesterday.

Examples

StartDate=TOMORROW
EndDate=20101020-20101031
Comments