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

Aman Kumar S
Kilo Patron

Hey,

var gdt = new GlideDateTime();

gdt.addYears(2);

gs.info(gdt);

 

If you want to add 1 day as well, add this line as 3rd line in the code:

gdt.addDays(1);

Best Regards
Aman Kumar

Hi,

 

 

Var gdt = new GlideDateTime();

gdt.addYears(2);
gdt.addDays(1);

 

I am receiving below error,

 

find_real_file.png

You should have told you are writing a client script, this only works in server side.

Best Regards
Aman Kumar

I have pasted in my question, I am using client script