Why add days not working when using glide date function?

KM SN
Tera Expert
var today = new GlideDate();
gs.print(today);
var tmrw = today.addDaysUTC(1);
gs.print(tmrw);

tmrw is printing as undefined? what might be the reason for this?
2 ACCEPTED SOLUTIONS

Voona Rohila
Mega Patron
Mega Patron

Hi @KM SN 

Try this

var today = new GlideDate();
gs.print(today);
today.addDaysUTC(1);
gs.print(today);

 

addDaysUTC - Adds a specified number of days to the current object but doesn't return any value, so tmrw is showing as undefined

 

You can use the same object 'today' 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

Brad Bowman
Kilo Patron
Kilo Patron

Most of the handy functions available in GlideDateTime are not in GlideDate.  Use GlideDateTime, then you can get just the date from that if you want.

View solution in original post

3 REPLIES 3

Voona Rohila
Mega Patron
Mega Patron

Hi @KM SN 

Try this

var today = new GlideDate();
gs.print(today);
today.addDaysUTC(1);
gs.print(today);

 

addDaysUTC - Adds a specified number of days to the current object but doesn't return any value, so tmrw is showing as undefined

 

You can use the same object 'today' 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Docs Link - https://docs.servicenow.com/bundle/xanadu-api-reference/page/app-store/dev_portal/API_reference/Glid... 

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Brad Bowman
Kilo Patron
Kilo Patron

Most of the handy functions available in GlideDateTime are not in GlideDate.  Use GlideDateTime, then you can get just the date from that if you want.