+ Start a Discussion
bensondanielbensondaniel 

Calendar Question

If todays date could be retreived by

System.today();

How to calculate a date of the previous week

with the same day?

or

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.

 

Afzal