Hi Postman Pro`s,
i have an Endpoint which gives me an Timestamp, it shows like that:
The Problem is that the API on the other Site wants this Timestamp in 2 Values:
one Value for the Time in Format: HHMMSS / 115139
an the other Value for the Date in Format: YYYYMMDD / 20230728
I’ve already tried:
I tried to use a pre Request Script in the Second Request like that:
const moment = require(‘moment’);
This gives me the actual Time and Date but dont modify the Source Timestamp which is also a Collection Variable in the First Request.
I dont understand how to do what moment does but with my Timestamp as Source not the actual Time an Date.
Maybe someone can explain the right Way
I am a little bit further:
let res = pm.response.json();
let date = res.gpsTime.split(‘T’);
let time = res.gpsTime.split(‘T’).slice(0,8);
But how i can get out the : and - ???
You need to pass in the response timestamp to the moment function.
let responseTimestamp = "2023-07-28T11:51:39+00:00";
// you need to retrieve this element from your response
const moment = require("moment");
let timestamp1 = moment(responseTimestamp).format("YYYYMMDD");
console.log(timestamp1); // "20230728"
let timestamp2 = moment(responseTimestamp).format("hhmmss"); // needs to be lowercase
console.log(timestamp2); // "115139"
Thank you for your answer, it works perfectly. Oh man sometimes you’re blind on both eyes, I’m still learning.
I’ve read so many threads and pulled my hair out, the answer was probably just too simple.
No probs, glad its now working for you.