Question

Assume today is wed, first of may, 2014. I want to get date of last week Mon.

$CurrentDay = date(l);
if ($CurrentDay == "Monday" AND $CurrentDay != "Wednesday" ) { 
   $AdjustedDate = date(j)-3; 
   $SetDate = $AdjustedDate."/".date(m)."/".date(Y);  
} 

It all goes well till the date is like "1" or something like that the value is "-".

Was it helpful?

Solution

try to minus your days with current date

echo $CurrentDay = date(l); //Friday
if($CurrentDay) { 
echo $AdjustedDate = date('d/m/Y l', strtotime('last Week Monday', strtotime($CurrentDay)));     
//28/04/2014 Monday 

OTHER TIPS

If you want to calculate past monday, use this:

$timestamp = time();
$monday = idate('w', $timestamp) == 1 ? $timestamp : strtotime("last Monday", $timestamp);

Now you got the Timestamp of the monday, and you can just do:

echo date("d/m/Y", $monday);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top