How to add two years to a dates

Surya67
Tera Contributor

Hi,

 

I need to update date field as tomorrow + 2years.

if I am submitting the form on 2 May 2022, it should display tomorrow + two years. after date is added field should be readonly

I am using below code in client script

gdt = new GlideDateTime().getDisplayValue();

gdt.addYears(2);

gdt.adddays(1);

gdt.getDate();

 

I am receiving errors in console

 

My scope is Human Resource

12 REPLIES 12

Hi,

so you can use default value in the variable and it would show up when form loads

javascript: var date; var nowTime = new GlideDateTime(); nowTime.addDaysUTC(1); nowTime.addYearsUTC(2); date = nowTime.getDate(); date;

regards
Ankur

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

@Surya

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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

asifnoor
Kilo Patron

Hi Surya,

Then you canuse the default value  as suggested by Ankur.

If you want the value to be shown considering a schedule, then refer to this link.

https://community.servicenow.com/community?id=community_article&sys_id=4c66ff4a1bde08107a5933f2cd4bc...

https://community.servicenow.com/community?id=community_article&sys_id=c1f86b0a1b1e08107a5933f2cd4bc...