pvitt
pvitt

Reputation: 1065

Can't Parse JSON Date from SQL Server in Javascript

Im getting a JSON date back from SQL Server that looks like this:

"/Date(-62135568000000-0800)/"

when I try to parse the date using: var date = new Date(parseInt(MyDate) * 1000); I get Invalid Date

ultimately I'm trying to put these dates on an x axis of d3 time series plot.

Is there a way I can use this JSON date value in d3?

EDIT:

I found a work-around on the SQL Server side by returning the number of seconds since 1/1/1970 as an int

Upvotes: 1

Views: 1071

Answers (1)

Rashmin Javiya
Rashmin Javiya

Reputation: 5222

You can try this function

function GetJSDateFromMS(str)
{
    return eval("new " + str.replace(/\//g,""));
}

Pass datetim string varibale to function and it will return you a Javascript datetime object.

GetJSDateFromMS("/Date(345345345345)/")

Thu Dec 11 1980 06:45:45 GMT+0530 (India Standard Time)

Upvotes: 1

Related Questions