Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

addDaysLocalTime() shows undefined

adityavishnu
Giga Expert

Why does the below code returns undefined? I tried this in Background- Scripts and Business Rule with same result.

date();
function date()
{
var gd = new GlideDateTime("2018-04-18 00:31:57");
gs.print(gd.addDaysLocalTime(28));
}
4 REPLIES 4

Not applicable

Hi Aditya,

After var gd = new GlideDateTime("2018-04-18 00:31:57");

Add gd.addDaysLocalTime(28);

And then gs.print(gd.getLocalDate());

 // Output: 2018-04-18

Mark If Helpful

Thank You

Mahendra RC
Mega Sage

Hi 

I think you are printing wrong value, could you please check as shown below:

date();
function date()
{
var gd = new GlideDateTime("2018-04-18 00:31:57");
gd.addDaysLocalTime(28);
gs.print(gd);
}

Please mark it correct, if it resolves your problem.

Thanks

sk4408bc
Tera Contributor

I am having the same issue. Please could someone help?

var gdt = new GlideDateTime();
gdt = gs.beginningOfNextWeek();
gdt.addDaysLocalTime(2);
gs.info("2 days added is: " + gdt);
gs.print(gdt);

Output:
*** Script: 2 days added is: 2025-07-14 00:00:00
*** Script: 2025-07-14 00:00:00
The function to add 2 days, seem to not work. 

sk4408bc
Tera Contributor
var gdt = new GlideDateTime();
gdt = gs.beginningOfNextWeek();
gs.info(gdt);
gdt.addDaysLocalTime(2);
gs.info("2 days added is: " + gdt);
gs.print(gdt);

Output:
*** Script: 2025-07-14 00:00:00
*** Script: 2 days added is: 2025-07-14 00:00:00
*** Script: 2025-07-14 00:00:00

The function to add 2 days, seem to not work.