Warm tip: This article is reproduced from serverfault.com, please click

其他-增加天数到php当前的Date()

(其他 - Increase days to php current Date())

发布于 2008-11-10 06:59:24

如何在PHP中向当前日期添加一定天数?

我已经知道了当前日期:

$today = date('y:m:d');

只需添加x天数

Questioner
Anomynous
Viewed
11
9,964 2020-04-09 20:30:58

php支持c风格的日期函数。你可以通过strtotime函数用英语样式短语添加或减去日期间隔例子...

$Today=date('y:m:d');

// add 3 days to date
$NewDate=Date('y:m:d', strtotime('+3 days'));

// subtract 3 days from date
$NewDate=Date('y:m:d', strtotime('-3 days'));

// PHP returns last sunday's date
$NewDate=Date('y:m:d', strtotime('Last Sunday'));

// One week from last sunday
$NewDate=Date('y:m:d', strtotime('+7 days Last Sunday'));

或者

<select id="date_list" class="form-control" style="width:100%;">
<?php
$max_dates = 15;
$countDates = 0;
while ($countDates < $max_dates) {
    $NewDate=Date('F d, Y', strtotime("+".$countDates." days"));
    echo "<option>" . $NewDate . "</option>";
    $countDates += 1;
}
?>