GlideDateTime method addSeconds() seems not to be working

dp11
Tera Guru

Hi,

I am trying to use the addSeconds() method in the following way:

var x = new GlideDateTime(current.due_date);
gs.log("x: " + x.getValue());

var y = new GlideDateTime(x);

gs.log("y: " + y.getValue());

var z = y.addSeconds(3600);

gs.log("z: " + z.getValue());

The values for x and y prints out fine. The value for z prints as 'undefined'. Please let me know if there is something wrong in it.

Thanks!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Dp,

Try this and check below. the method addSeconds doesn't return anything so it is giving undefined

var x = new GlideDateTime(current.due_date);
gs.log("x: " + x.getValue());

var y = new GlideDateTime(x);

gs.log("y: " + y.getValue());

y.addSeconds(3600);

gs.log("z: " + y.getValue());

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Shishir Srivast
Mega Sage

Please check if this helps,

var x = new GlideDateTime(current.due_date);
gs.log("x: " + x.getValue());
var y = new GlideDateTime(x.getValue());
gs.log("y: " + y.getValue());
y.addSeconds(3600);
gs.log('new time' + y.getValue());

Thanks Shishir. I overlooked the aspect that addSeconds did not return any value.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Dp,

Try this and check below. the method addSeconds doesn't return anything so it is giving undefined

var x = new GlideDateTime(current.due_date);
gs.log("x: " + x.getValue());

var y = new GlideDateTime(x);

gs.log("y: " + y.getValue());

y.addSeconds(3600);

gs.log("z: " + y.getValue());

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks Ankur! I overlooked the fact that addSeconds() did not return any value.