How would you convert milliseconds to a date in the datamapper?
Would like to used the date field type so I can utilize the date in multiple formats.
For example ‘1612285919580’ would be ‘Tue 2 February 2021 11:11:59’
How would you convert milliseconds to a date in the datamapper?
Would like to used the date field type so I can utilize the date in multiple formats.
For example ‘1612285919580’ would be ‘Tue 2 February 2021 11:11:59’
Use this script:
(new Date(1612285919580)).toISOString();
This creates a string value with a fixed ISO format. You then simply set your Field type to Date and set the Date/Time Format value to yyyy-mm-ddThh:nn:ms
. That will create a true Date field that you can format any which way you like.
Works great if I use the static value 1612285919580, however when I try to use the extracted data value I get script error of date invalid. Not sure what I’m missing
Even if TIMESTAMP contains the same value of 1612285919580 if errors out. The next record would contain something different such as 1512285919580 for Sun 3 December 2017 01:25:19
var mydate = data.extract('TIMESTAMP',0);
(new Date(mydate)).toISOString();
This should work:
var myDate = parseFloat(data.extract('TIMESTAMP',0));
(new Date(myDate)).toISOString();
I didn’t try parseFloat, but it makes sense.
Thanks