function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

add a year in apex

This is a ridiculously simple question and just involves date formatting.  Hoping one of the brains on here can figure this out before I do.


I just want to add 1 year to the current year.


So if I've got


String str=dt.format('yyyy');


I just want to add 1 year to that string, so I can refer to it in my code.  That's it.


This has got to be super easy I just am too dumb to see it yet.


Thanks guys




You can use addYears() method of DataTime.


DateTime newDate = System.Now().addYears(1);


DateTime Methods documentation:


Hope this helps :)






Jerun JoseJerun Jose
Integer nextYear = + 1;
Date dt= Date.newInstance(datefield.year()+1, datefield.month(), datefield.Day());