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

Increase days to php current Date()

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

How do I add a certain number of days to the current date in PHP?

I already got the current date with:

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

Just need to add x number of days to it

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

php supports c style date functions. You can add or substract date-periods with English-language style phrases via the strtotime function. examples...

$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'));

or

<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;
}
?>