Add 1 year to current date in date field

codedude
Mega Expert

I have a date field where I am currently setting the defualt value to todays date using javascript:now();. I am unable to figure out how to set the defualt value to todays date + 1 year....  

Can someone please help me with this?

8 REPLIES 8

Is there a way for me to make this function to where if the topic is "News" then it will add 30 days, else it will add a year like you did above?


please try it


i hope, it as your expected.


var d = new GlideDateTime(gs.nowDateTime()); current.topic == "News" ? d.addDays(30) : d.addYearsLocalTime(1); d.getDisplayValue();


Gurpreet07
Mega Sage

javascript:gs.yearsAgo(-1)       will work


Jaspal Singh
Mega Patron
Mega Patron

Hi Josh,



Set default value for field as javascript:var gdt = new GlideDateTime(gs.nowDateTime());gdt.addYears(1);gdt.getDate();