Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
QlikWorld happening right now! You can still join: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
tmumaw
Specialist II
Specialist II

Convert JSON Date to Real Date

how can I convert this json date to a real date?  Thanks

/Date(1429192143000+0000)/

1 Solution

Accepted Solutions
fostercarly
Contributor
Contributor

JSON does not know anything about dates. What .NET does is a non-standard hack/extension. The problem with dates in JSON and really JavaScript in general – is that there's no equivalent literal representation for dates. In JavaScript following Date constructor straight away converts the milliseconds since 1970 to Date as follows:

var jsonDate = new Date(1297246301973);

Then let's convert it to js format:

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

The substr() function takes out the /Date( part, and the parseInt() function gets the integer and ignores the )/ at the end. The resulting number is passed into the Date constructor .

 

View solution in original post

4 Replies
hectormunoz
Contributor III
Contributor III

Hi

if I'm not wrong, that value is 04/16/2015 @ 1:49pm (UTC) (from https://www.unixtimestamp.com/index.php)

If this is correct, you can use this

Timestamp(MakeDate(1970) + subfield(vDateField,'+',1)/1e3 / (24 * 60 * 60))

Regards 

georgio_hb
Contributor III
Contributor III

What's the "1e3" part ? 

Qliksense is not recognizing it neither on the front or the back end.

Did you manage to get it to work ? 

hector
Specialist
Specialist

Hi

1e3 = 1000 cause is in scientific notation (1 x 10^3). Because Unix timestamps are in milliseconds, so milliseconds/1e3=seconds

 

regards

fostercarly
Contributor
Contributor

JSON does not know anything about dates. What .NET does is a non-standard hack/extension. The problem with dates in JSON and really JavaScript in general – is that there's no equivalent literal representation for dates. In JavaScript following Date constructor straight away converts the milliseconds since 1970 to Date as follows:

var jsonDate = new Date(1297246301973);

Then let's convert it to js format:

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

The substr() function takes out the /Date( part, and the parseInt() function gets the integer and ignores the )/ at the end. The resulting number is passed into the Date constructor .