PHP, Get tomorrows date from date

PHP, Get tomorrows date from date

Asked on December 25, 2018 in PHP.
Add Comment


  • 3 Answer(s)

    By using DateTime() function, one can get the solution in various versions of php,

    $datetime = new DateTime('tomorrow');
    echo $datetime->format('Y-m-d H:i:s');
    

    Or:

    $datetime = new DateTime('2013-01-22');
    $datetime->modify('+1 day');
    echo $datetime->format('Y-m-d H:i:s');
    

    Or:

    $datetime = new DateTime('2013-01-22');
    $datetime->add(new DateInterval("P1D"));
    echo $datetime->format('Y-m-d H:i:s');
    

    In PHP 5.4+ and later versions:

    echo (new DateTime('2013-01-22'))->add(new DateInterval("P1D"))
                                     ->format('Y-m-d H:i:s');
    
    Answered on December 25, 2018.
    Add Comment

    Try to use the code below which is contained strtotime() function.

    $tomorrow = date("Y-m-d", strtotime('tomorrow'));
    

    Otherwise, try this code,

    $tomorrow = date("Y-m-d", strtotime("+1 day"));
    

    For know more about strtotime().

    Answered on December 25, 2018.
    Add Comment

    Insert this one line of code in the actual code, we can get the solution easily.

    <? php
    //1 Day = 24*60*60 = 86400
    echo date("d-m-Y", time()+86400);
    ?>
    
    Answered on December 25, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.