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

Calendar Question

If todays date could be retreived by;

How to calculate a date of the previous week

with the same day?


If today is tuesday and the date is 19th April

How to calculate the date of last Tuesday?

The answer which we are expecting is 12th of April.


Can anyone suggest an efficient formula?


Best Answer chosen by Admin (Salesforce Developers) 
Afzal MohammadAfzal Mohammad

You may do something like this.



date myDate = System.Today();
date previousWeek = mydate.addDays(-7);
date nextWeek = mydate.addDays(7);



Hope that helps.