简体   繁体   English

在php中选择最后5个日期

[英]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. 我不知道如何从当前日期选择最后5个日期。 is there any option notify me how to select last 5 date from present date. 是否有任何选项通知我如何从当前日期选择最后5个日期。 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. strtotime可以做到这一点。

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

You can use function date and strtotime :) 您可以使用函数date和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
$tomorrow  = mktime(0, 0, 0, date("m")  , date("d")+1, date("Y"));

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

this should do, if i understood your question correctly: 如果我正确理解了您的问题,就应该这样做:

echo strtotime("-5 day");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM