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
degmodegmo 

Date calculation in Apex

Hi,
I have a requirement where I need to calculate a date that is one year from today.  The new date has to be same month, same week, and same day for next year.

For example, today is 5/4/2021 which is the 5th month of the year, 1 week of the month, and 4th day of the week.  I am thinking I can do this by just adding 365 to the date.  Is that correct or does anyone see an edge case that could make this incorrect?
AbhinavAbhinav (Salesforce Developers) 
Hi Degmo,

You can try this:
Date currentDate =System.today();
Date dt= Date.newInstance(currentDate.year()+1, currentDate.month(), currentDate.Day());

System.debug('******'+dt);//2022-05-04 00:00:00

Please mark it best answer if its helps  or do let me know if you have any queries.

Thanks!