PHP - add 1 day to date format mm-dd-yyyy

前端 未结 6 445
无人共我
无人共我 2020-12-09 01:30

相关标签:
6条回答
  • 2020-12-09 01:44

    use http://www.php.net/manual/en/datetime.add.php like

    $date = date_create('2000-01-01');
    date_add($date, date_interval_create_from_date_string('1 days'));
    echo date_format($date, 'Y-m-d');
    

    output

    2000-01-2
    
    0 讨论(0)
  • 2020-12-09 01:45
    $date = strtotime("+1 day");
    echo date('m-d-y',$date);
    
    0 讨论(0)
  • 2020-12-09 01:52

    The format you've used is not recognized by strtotime(). Replace

    $date = "04-15-2013";
    

    by

    $date = "04/15/2013";
    

    Or if you want to use - then use the following line with the year in front:

    $date = "2013-04-15";
    
    0 讨论(0)
  • 2020-12-09 01:58

    Actually I wanted same alike thing, To get one year backward date, for a given date! :-)

    With the hint of above answer from @mohammad mohsenipur I got to the following link, via his given link!

    Luckily, there is a method same as date_add method, named date_sub method! :-) I do the following to get done what I wanted!

    $date = date_create('2000-01-01');
    date_sub($date, date_interval_create_from_date_string('1 years'));
    echo date_format($date, 'Y-m-d');
    

    Hopes this answer will help somebody too! :-)

    Good luck guys!

    0 讨论(0)
  • 2020-12-09 02:04

    there you go

    $date = "04-15-2013";
    $date1 = str_replace('-', '/', $date);
    $tomorrow = date('m-d-Y',strtotime($date1 . "+1 days"));
    
    echo $tomorrow;
    

    this will output

    04-16-2013
    

    Documentation for both function
    date
    strtotime

    0 讨论(0)
  • 2020-12-09 02:04
    $date = DateTime::createFromFormat('m-d-Y', '04-15-2013');
    $date->modify('+1 day');
    echo $date->format('m-d-Y');
    

    See it in action

    Or in PHP 5.4+

    echo (DateTime::createFromFormat('m-d-Y', '04-15-2013'))->modify('+1 day')->format('m-d-Y');
    

    reference

    • DateTime::createFromFormat()
    0 讨论(0)
提交回复
热议问题