开发者

To select last 5 date in php

I am using

$todayDate = date('Y-m-d');

To Fetch todays date.

开发者_开发问答

I dont know how to select last 5 date from present date. is there any option notify me how to select last 5 date from present date. Thanks in advance


$dates = array();
for ($i = 0; $i < 5; $i++) {
    $dates[] = date('Y-m-d', strtotime("-$i days"));
}

print_r($dates);


strtotime can do this.

$five_days_ago = strtotime('-5 days');
$five_days_formatted = date('Y-m-d', $five_days_ago);


$tomorrow  = mktime(0, 0, 0, date("m")  , date("d")+1, date("Y"));


http://www.php.net/manual/en/function.strtotime.php

this should do, if i understood your question correctly:

echo strtotime("-5 day");


You can use function date and strtotime :)

$fiveDaysFuture = date('Y-m-d', strtotime('+5 days', strtotime(date('Y-m-d'))));//future
$fiveDaysAgo = date('Y-m-d', strtotime('-5 days', strtotime(date('Y-m-d'))));//ago
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜