Domanda

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?

È stato utile?

Soluzione

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

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top