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
hogehogehogehoge 

Help me this error

Error message
Method does not exist or incorrect signature: void addMonth(Integer) from the type Date.

How can I fix it?

 
​​​​​​​        Date day = Date.today();
        Date startDate = Date.newInstance( day.year() - ( day.month() < 4 ? 1 : 0 ) , ( day.month() >= 4 || day.month() <= 9 ) ? 4 : 10 , 1 );
        Date endDate = startDate.addMonth( 6 ).addDay( - 1 );

 
AnkaiahAnkaiah (Salesforce Developers) 
Hi 

try with below.
        Date day = Date.today();
        Date startDate = Date.newInstance( day.year() - ( day.month() < 4 ? 1 : 0 ) , ( day.month() >= 4 || day.month() <= 9 ) ? 4 : 10 , 1 );
        Date endDate = startDate.addMonths( 6 ).addDay( - 1 );
If this helps, Please mark it as best answer.

​​​​​​​Thanks!!
 
hogehogehogehoge
Thank you. I entered the above code, but the error could not be resolved.
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

try with below code. its working..
Date day = Date.today();
        Date startDate = Date.newInstance( day.year() - ( day.month() < 4 ? 1 : 0 ) , ( day.month() >= 4 || day.month() <= 9 ) ? 4 : 10 , 1 );
        Date endDate = startDate.addMonths( 6 ).addDays( - 1 );
system.debug('endDate=='+endDate);

If this helps, Please mark it as best answer.

Thanks!!