Question

I find functions which return the week number for a given date. But instead, I would like to get the date of the first day of the particular calendar week returned. This would either be date() itself, or anything between date()-1 and date()-7.

Purpose: my site shall return events of this week. Right now, I only show the the range date()+7, which is not correct.

Thanks & Regards, Marcus

Était-ce utile?

La solution

Use strtotime() function like this:

strtotime("next monday");
strtotime("this sunday");
strtotime("last sunday"); 

In your case:

strtotime("this monday");

As a result you have timestamp.

The second way is like this:

$day = date('w');
$week_start = date('m-d-Y', strtotime('-'.$day.' days'));
$week_end = date('m-d-Y', strtotime('+'.(6-$day).' days'));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top