My question:
how to convert in a test a date retrived from SAP from Unix Timestamp to iso date.
Details (like screenshots):
Hello to all.
i would like to test if a date retrived from SAP is the same as the one i wanted. i read data with a get (JSON) but the date is retrived in Unix timesamp format. So i started to find a formula to convert it. In excel the formula is (date in unix/86400000)+DATE(1970;1;1) but i would like to do it directly in Postman.
my issue is that SAP retrived me the data like this:

how can i get just 1516147200000 to convert it or is there a function to convert directly the date ??
i tried to work from this with:

work well for the date of the day…
thank you in advance for your help.
Hey @adrienbouygues
Welcome to the Postman Community 
Would the following script work?
const moment = require('moment')
const isoDate = moment(1516147200000).format('YYYY-MM-DD')
Hope this helps, but please do let me know if this is not what you are after 
1 Like
Hello @taehoshino thank you very much!!
The following script is working well for the conversion thank you very much.
My other issue is that my date is retrived this way:
“date”: “/Date(1528588800000)/”
do you have any idea to get directly the unix number: 1528588800000 ?
Thanks again
1 Like
Hey @adrienbouygues 
Glad to hear that it helped!
I understand the response is JSON, correct? Then you can do something like below?
const response = pm.response.json()
const date = response.date // this is to access "date" property of JSON response
const dateTimeStamp = date.split(/\(|\)/g)[1] // this is splitting the "date" string using regular expression
2 Likes
Hello,
I have a similar issue… Few of the JSON string are in epoach format… Could you please tell me how do i convert it into DD/MM/YYYY format manually
Adding the screenshot
Hello @shivanip12 ,
If you would like to convert the date to a iso date you can apply this formula in excel
=(A1/86400000)+DATE(1970;1;1). A1 is the date you get from your body response.
I hope this help.
1 Like
Hello @adrienbouygues,
Thanks it helped… Is there any way we can convert it within postman?