开发者

What days contain in this week [duplicate]

This que开发者_如何转开发stion already has answers here: Closed 11 years ago.

Possible Duplicate:

Get Start and End Days for a Given Week in PHP

Example i use function date('W') will get week of the year. Suppose get week number 37. Can I get what days in this week Example 2011-09-12 to 2011-09-18

Thank you


You can use the DateTime and DatePeriod classes to work with dates and periods of time.

// ISO week to get the days of
$week = '2011W37';

// Date period for the days in the above week
$period = new DatePeriod(new DateTime($week), new DateInterval('P1D'), 6);

foreach ($period as $day) {
    echo $day->format('Y-m-d') . PHP_EOL;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜