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
PrazPraz 

Subtracting days in apex classes

Hi,

 

I have a requirement to find the Friday of this week and then find the Friday before 13 weeks. How can I do that. To find the current friday I did the following

 

this.dateView.Pack__Start_Date__c = date.today().toStartOfWeek().addDays(6);

 

Now how can I get the 13 week before date? as there is no date subtraction function here. So please tell me how can it be done in Apex classes

Best Answer chosen by Admin (Salesforce Developers) 
SPDSPD

then i guess this should work....

 

 addDays(-91)....this will take care of leap year....as it only counts the days.... i dont know whether there is any other way.... but you may go on to explore and please let me know if it is posssible by some other way...

All Answers

SPDSPD

yes you can...

 

this.dateView.Pack__Start_Date__c.addDays(-13);

PrazPraz
But I need the date 13 th week before not 13 days before...except subtracting 91 days(13*7) is there any other way.. this logic should also take care of leap year condition for 29th Februray as well..
SPDSPD

then i guess this should work....

 

 addDays(-91)....this will take care of leap year....as it only counts the days.... i dont know whether there is any other way.... but you may go on to explore and please let me know if it is posssible by some other way...

This was selected as the best answer
PrazPraz
Tnx a lot