The CreatorCon Call for Content is officially open! Get started here.

Add 30 Days to Expected Date

Community Alums
Not applicable

Hi All,

Need assistance on adding 30 days to expected date

we have multiple formats of date YYYY-MM-DD or DD/MM/YYYY or DD-MM-YYYY or MM-DD-YYYY

I would help with script where Field A should any format as per user profile, however should be able to calculate as setvalue + plus 30days date with format of User profile.

Key role: User profile date format.

Eg: User: Crish | FIeld A: 2017-07-24 | FIeld B should be 2017-08-23

Eg: User: Veer | FIeld A: 25/07/2017 | FIeld B should be 24/08/2017

2 REPLIES 2

Karthik Reddy T
Kilo Sage

Hello Vamsi,



Refer the below script may helpful to you.



  var myValidTo = current.valid_to;                                              


    myValidTo = myValidTo.toString() + ' 00:00:00';


    var gdt = new GlideDateTime(myValidTo);


    gdt.addDays(30);


    var gdtStr = gdt.toString();


    var reminderOnStr = gdtStr.substring(8, 10) + '-' + gdtStr.slice(5,7) + '-' + gdtStr.substring(0, 4);


    current.u_reminder_on = reminderOnStr.



Adding 30 days to a date field when another field changes



Set date field value on change




Set Default Value of a date field to 30 days from today


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

Harsh Vardhan
Giga Patron

Hi Vamsi,



you can use addDays();



var nd = new GlideDateTime(gs.nowDateTime());


gs.print('current date is :'+nd);


var fd = new GlideDateTime(nd);


fd.addDays(30);


gs.print('future date will be:'+fd);



find_real_file.png



Hope it will help you