addDays is not working

smondal
Kilo Explorer

Hi everyone,

I have written the below piece of code.

bit it is not working.

Can anyone please help me on that.

 

var time=current.u_meeting_date;

  var gdt = new GlideDateTime(time);

  gs.addInfoMessage(gdt);//this is coming

  var timeupdated=gdt.addDays(7);

  gs.addInfoMessage(timeupdated);//org.mozilla.javascript.Undefined@4964c7 error

 

Many thanks in Advance.

9 REPLIES 9

TJW2
Mega Guru

Try adding the .getDate() as in the WIKI article:


GlideDateTime - ServiceNow Wiki



var gdt = new GlideDateTime("2011-08-31 08:00:00");


gdt.addDays(-1);


gs.print(gdt.getDate());


yes i already tried.


that thing is working fine.


but when i tried fetch a date then want to add that is not working.


Earl L
Mega Guru

Are you using two different variable for your date/time value? You first set the retrieved value to the "time" variable but then you update the "timeupdated" variable for the updated date/time.



If you're expecting to update the value that your retrieved then you have your calculation in the wrong place. Or perhaps I'm misunderstanding what you're trying to do.



Earl


hey,


Please help me to add days.



var time=current.u_meeting_date;//fetching the date and time


  var gdt = new GlideDateTime(time);


  gs.addInfoMessage(gdt);//this is coming


  var timeupdated=gdt.addDays(7);//try to add 7 days


  gs.addInfoMessage(timeupdated);//just to display the value which is retriving



Regards,


Swapnali