Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How do use gs.monthsAgoStart?

zsquared
Tera Contributor

Hello,

I am having trouble understanding how to use the gs.monthsAgoStart()

I am just trying to find the date 3 months from today.

var newTime = new GlideDateTime();  

  var startTime = gs.monthsAgoStart(3);

Not sure where I am supposed to put my newTime variable..

5 REPLIES 5

Abhinay Erra
Giga Sage

Here you go



var newTime = new GlideDateTime();      


newTime.addMonthsLocalTime(3);


var startTime= newTime.getValue();


rlatorre
Kilo Sage

monthsAgoStart gives you the first day of the month 3 months ago.



Example:


var date = gs.monthsAgoStart(3);


gs.print(date);


Gives a result of August 1st, 2016 if run during November 2016



You should use monthsAgo.



Example:


var date = gs.monthsAgo(3);


gs.print(date);


Gives a result of August 10th 2016 if run today November 10th 2016



Note: The result is in GMT and includes the time as well


For some reason, my date is not printing when I try to do this:


var newTime = gs.monthsAgoStart(3);
var endTime = gs.monthsAgoEnd(3);

tasks.addQuery('u_aom_estimated_remaining_hour','>=', startTime);


tasks.addQuery('u_aom_estimated_remaining_hour','<=', endTime);



Not sure what I am doing wrong.   I see valid data from the queried table that should be pulled.


You might be using the wrong variable   change startTime to newTime