I'm trying to get the current date - 3 months and use it in a postman Pre-request script. I'm told it uses javascript, but it doesn't seem to be working.
The error I get is:
There was an error in evaluating the Pre-request Script: TypeError: startDate.setMonth is not a function
Here is what I have:
// setup start date
var startDate = Date();
startDate.setMonth(startDate.getMonth() - 3);
I'm trying to get the current date - 3 months and use it in a postman Pre-request script. I'm told it uses javascript, but it doesn't seem to be working.
The error I get is:
There was an error in evaluating the Pre-request Script: TypeError: startDate.setMonth is not a function
Here is what I have:
// setup start date
var startDate = Date();
startDate.setMonth(startDate.getMonth() - 3);
Share
Improve this question
edited Oct 17, 2018 at 1:00
jasonscript
6,1783 gold badges30 silver badges45 bronze badges
asked Apr 19, 2018 at 17:59
user117499user117499
3 Answers
Reset to default 4https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Syntax
JavaScript Date objects can only be instantiated by calling JavaScript Date as a constructor: calling it as a regular function (i.e. without the new operator) will return a string rather than a Date object; unlike other JavaScript object types, JavaScript Date objects have no literal syntax.
so
Date();
needs to be
new Date();
Try change var startDate = Date();
to var startDate = new Date();
As an alternative, Postman es with the moment module built in so you could do something like this:
var moment = require("moment")
var startTime = moment().subtract(3, 'months')
Or you could obviously use native JavaScript, worth knowing a couple of different ways though.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745636424a4637421.html
评论列表(0条)