How to add hours to a Date/Time value in widget client_script

siva mani kanta
Tera Expert

Hi All,

How to add current date + 72 hr in client script. in widgets.

 

reagrds,

siva

2 REPLIES 2

Community Alums
Not applicable

Hi @siva mani kanta reddy ,

You might want to use getDisplayValue() to get in the user's time zone

var gdt = new GlideDateTime(gs.beginningOfNextWeek());

var hours = 60*60*72;

gdt.addSeconds(hours);

gs.print(gdt.getDisplayValue());

 

And this is how you run this client script on widget:

https://community.servicenow.com/community?id=community_question&sys_id=a8161c08dbb59c504819fb2439961982

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

Avinash_Patil1
Giga Guru

Hi Siva,

you can perform the same operation on server side and pass that value to Client-side.

var gdt = new GlideDateTime();
console.log('current date'+gdt);
var hours = 259200;//72 hours
gdt.addSeconds(hours);
console.log('new date:'+gdt.getDisplayValue());