Calculating relative dates in php using strtotime ()

I'm looking for a reliable way to return the full date of a specified day of the week (for example, "Mon") to the current week.

From today on Wednesday, June 13, 2012, I expected it to <?php echo date("Y-m-d", strtotime('Mon this week')); ?>result in 2012-06-11, but instead, php returns 2012-06-18as if it will interpret this week as a value next week . Why is this behavior and what should I do?

Thank.

- Jeff

+5
source share
3 answers

date( 'Y-m-d', strtotime( 'last Monday', strtotime( 'Sunday' ) ) );

This is a search Monday until next Sunday.

+5
source

According to the documentation, relative date formats are in php format .

Monday this week next Monday, this week.

dayname: , , . , 11 , strtotime('Monday this week') 11 , 13 , strtotime('Monday this week') 19 .

+2

I think this is the solution to your problem:

$monday_date = date("Y-m-d", mktime(0,0,0, date("m"), date("j")-(date("w")+1), date("Y")));
0
source

All Articles