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 to add hours to start date

Shilpi Sharma2
Tera Contributor

Hi All,

 

i  have a start date :2020-02-19 04:57:49 how to add 12 hours to this date as gs.hoursAgo() adding hour to system date. Please help

3 REPLIES 3

Munender Singh
Mega Sage

Hi Shilpi,

 

Kindly use this piece of code:

var gdt = new GlideDateTime();


gdt.setDisplayValue(current.start_date.getDisplayValue());


gdt.addSeconds(43200); //add 12 hour (can do for more by multiplying with 3600 factor)


var result=gdt.getDisplayValue(); //this will get you the new glideDatetime

 

Regards,

Munender

Dubz
Mega Sage
var gdt = new GlideDateTime(current.start_date);
var hours = 60*60*12;
gdt.addSeconds(hours);
gs.log(gdt.getDisplayValue()):

Sukraj Raikhraj
Kilo Sage