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

Calculate based on Calendar



I want to calculate date based on calendar.

I think that use Date.

Date initdate = '2010-02-19 00:00:00';

  Date updatedate;

updatedate = initdate.addYears(1);  //want to know next year's day 


But I dought [Date.addYears()] is adiing numeric '1' to only year'2010'.

That reault is  updatedate'2011-02-10 00:00:00'.


Do I must to create a logic? example:date calc

Or  can I user any method?


please tell me.





If I want to calculate date based on calendar in apex code,

I think to use Date.addDaye(1). 

But I want to add months or years, Date.addMonths(1), Date.AddYears(1),

that is'nt add date, I think that add numeric.


Case 1: add day(1 days later)


Case 2: add months(1 month later)


Case 3: add years(1 year later) 



When case2 and 3 , that code is correctly?

Please tell me for correct method.