문제

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 "-".

도움이 되었습니까?

해결책

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 

다른 팁

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top