我正在使用在php中選擇最後5個日期
$todayDate = date('Y-m-d');
來獲取今天的日期。
我不知道如何從現在的日期開始選擇最後5個日期。有沒有選項通知我如何從現在的日期選擇最後5個日期。 在此先感謝
我正在使用在php中選擇最後5個日期
$todayDate = date('Y-m-d');
來獲取今天的日期。
我不知道如何從現在的日期開始選擇最後5個日期。有沒有選項通知我如何從現在的日期選擇最後5個日期。 在此先感謝
$dates = array();
for ($i = 0; $i < 5; $i++) {
$dates[] = date('Y-m-d', strtotime("-$i days"));
}
print_r($dates);
strtotime
可以做到這一點。
$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"));
您可以使用功能日期的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
打我吧... :)必須承認,你的更優雅,缺乏文檔鏈接,雖然 –
嗯,他確實似乎是要求一個日期範圍。我在心裏過濾掉了。 – Charles
@Charles同上。 – Kyle