Increase current date by 5 days

后端 未结 11 1920
执笔经年
执笔经年 2021-01-02 16:57
$date = date(\'Y-m-d\',current_time(\'timestamp\', 0));

How do I change $date to $date + 5 days?

PHP version is 5

相关标签:
11条回答
  • 2021-01-02 17:28

    You can use

    strtotime(“+5 days”)
    

    to get the current date plus 5 days or

    $targetDate = date($date, strtotime(’+5 days’));
    
    0 讨论(0)
  • 2021-01-02 17:31

    strtotime() is very nice. It allows you to do the following:

    $startDate = 'now'; // or choose a certain date you want/have
    $startDate = '2013-02-14';
    $intervals = array(
        '', 
        '+ 5 days', 
        '+ 31 days', 
        '+ 3 months', 
        '+ 2 years + 2 days'
    ); 
    foreach($intervals as $interval) {
        $combinedDate = $startDate . ' ' . $interval;
        var_dump($combinedDate . ' => ' date('Y-m-d', strtotime($combinedDate)));
    }
    

    with a result:

    now => 1360334498 = 2013-02-08

    now + 5 days => 1360766498 = 2013-02-13

    now + 31 days => 1363012898 = 2013-03-11

    now + 3 months => 1368020498 = 2013-05-08

    now + 2 years + 2 days => 1423579298 = 2015-02-10

    or:

    2013-02-14 => 1360792800 = 2013-02-14

    2013-02-14 + 5 days => 1361224800 = 2013-02-19

    2013-02-14 + 31 days => 1363471200 = 2013-03-17

    2013-02-14 + 3 months => 1368478800 = 2013-05-14

    2013-02-14 + 2 years + 2 days => 1424037600 = 2015-02-16

    0 讨论(0)
  • 2021-01-02 17:31

    if the date is already exists, you can used this code :

    $tartDate = date("m/d/Y", strtotime("+1 Day", strtotime($Date)));
    
    0 讨论(0)
  • 2021-01-02 17:35

    Use strtotime:

    $date = date('Y-m-d', strtotime('+5 days'));
    
    0 讨论(0)
  • 2021-01-02 17:38
    $date = date('Y-m-d', strtotime('+5 days'));
    
    0 讨论(0)
提交回复
热议问题