How to find out last wednesday of month in PHP for PHP version 5.1.6 [duplicate]

StackOverflow https://stackoverflow.com/questions/21742964

  •  10-10-2022
  •  | 
  •  

문제

Is there any way in PHP to find out the last Wednesday of the current month? (or any day of the week for that matter)

For instance, the last Wednesday of this month (February 2014) is February 26, 2014

I know this would echo "February 2014"

echo date( 'F Y', strtotime( 'this month'));

This is my pseudo-code that doesn't work (it echoes "31 December 1969"):

echo date( 'd F Y', strtotime( 'last wednesday of this month'));

Any way to make this happen?

도움이 되었습니까?

해결책

$tsLast = strtotime( date('Y-m-01', strtotime('next month')).' last wednesday');
echo date(DATE_RFC850, $tsLast);

다른 팁

This seems to work:

  $nextMonthStart = mktime(0,0,0,date('m')+1,1,date('Y'));
  $last_wednesday = date("d F Y",strtotime("previous wednesday", $nextMonthStart)); 
  echo $last_wednesday;

got it from here: How do I find what day the last saturday of the current month is in PHP?

echo Date('Y-m-d',strtotime('last Wednesday of F'));

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top