0

I am trying to make an API call in Postman where I have to pass DateStart and DateEnd parameters. The date should be in the format yyyy-mm-ddThh:mm:ss. I tried the below but won't it just subtract 1 day from the current timestamp.

var moment = require('moment')

pm.environment.set("current_timestamp", moment().toISOString())
pm.environment.set("current_timestamp - 1 day", moment().subtract(1, 'day').toISOString())

Say for eg, if I make the API call today and want to retrieve the data for 'yesterday', then the date start variable should have a value of 2021-04-05T00:00:00 and date end variable should be 2021-04-06T00:00:00. The time should always be 00:00:00. How do I achieve this?

Thanks, Gowri

1 Answers1

0
var moment = require('moment')

a= moment().toISOString()
var m = moment().utcOffset(0);
m.set({hour:0,minute:0,second:0,millisecond:0})


console.log(m.format("YYYY-MM-DDTHH:mm:SS"))

Try this , use moment.set to set hour , minute etc

PDHide
  • 18,113
  • 2
  • 31
  • 46