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
  •  | 
  •  

Pergunta

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?

Foi útil?

Solução

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

Outras dicas

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'));

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top