views:

164

answers:

1

I have week number of current year and week day generated by date() like this.

$week_number = date('W');
$week_day = date('w');

I need to format this. How can I get starting date of this week? Or day of month with $week_number and $week_day?

+1  A: 

Update:

Maybe this article helps you. It describes how to get the start and end date of a given week.

<?php
// Monday
echo date(
    datetime::ISO8601,
    strtotime("2006W37"));

// Sunday
echo date(
    datetime::ISO8601,
    strtotime("2006W377"));
?>

Where the format is <year>W<week-number><daynumber> and Monday is 1.

Update 2:

Maybe another possibility is to use strtotime() this way:

echo strtotime("last Monday");
echo strtotime("next Sunday");

You can combine this with date() to get the date in the desired format.


You can get the day of the month with date('d') directly.

date() documentation.

Felix Kling
I know this function, but I get current day, I need get day of with given week number and week day.
Toktik
@Toktik: Ok, see my updated answer.
Felix Kling