Zulakis Zulakis - 25 days ago 10
PHP Question

How to find the day of week from a date using PHP?

If I've got a

$date
YYYY-mm-dd
and want to get a specific
$day
(specified by 0 (sunday) to 6 (saturday)) of the week that
YYYY-mm-dd
is in.

For example, if I got
2012-10-11
as
$date
and
5
as
$day
, I want to get
2012-10-12
, if I've got
0
as
$day
,
2012-10-14


EDIT:

Most of you misunderstood it. I got some date,
$date
and want to get a day specified by 0-6 of the same week
$date
is in.

So no, I don't want the day of
$date
...

Answer

I think this is what you want.

$dayofweek = date('w', strtotime($date));
$result    = date('Y-m-d', strtotime(($day - $dayofweek).' day', strtotime($date)));