0

My table displays the date in this format /Date(716841000000)/. I am storing date in yyyy-mm-dd format using SQL Server 2008. How can I get date in a proper format using JSON? This is my mapping function. I am unable to get the required date format

function OnSuccess(response) {
    var objdata = (response.d);
    var pm = JSON.parse(objdata);
    var len = objdata.length;
    arr = $.map(pm, function(n, i) {
      var arr_temp = {
        0: n.Id,
        1: n.name,
        2: n.gender,
        3: n.pincode,
        4: n.City,
        5: n.DOB,
        6: n.Id
      }
      arrtest[i] = n.Id;
      return arr_temp;
    });

dob column is not in proper format

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
user6885473
  • 298
  • 1
  • 5
  • 20
  • 1
    How you are returning it from `server`? Could you show us server side code? or you could also try `5: new Date(n.DOB),` in your `js`. – Guruprasad J Rao Jan 09 '17 at 08:10
  • For your ref http://stackoverflow.com/questions/22435212/angular-js-format-date-from-json-object – Raviteja Jan 09 '17 at 08:18
  • Possible duplicate of [Angular.js format date from json object](http://stackoverflow.com/questions/22435212/angular-js-format-date-from-json-object) – Raviteja Jan 09 '17 at 08:53

1 Answers1

1

Try this:

var date = new Date(parseInt(x.substr(6)));

JsFiddle

substr removes the /Date( part and parseInt ignores it at the end, passing the final result into the Date constructor.

function OnSuccess(response) {
  var objdata = (response.d);
  var pm = JSON.parse(objdata);
  var len = objdata.length;
  arr = $.map(pm, function(n, i) {
    var arr_temp = {
      0: n.Id,
      1: n.name,
      2: n.gender,
      3: n.pincode,
      4: n.City,
      5: n.DOB = new Date(parseInt(n.DOB.substr(6))),
      6: n.Id
    }
    arrtest[i] = n.Id;
    return arr_temp;
  });
}
urbz
  • 2,663
  • 1
  • 19
  • 29