How to increase date by 1 day in php?

I am using this this syntax to increase one day above but when i put this format it still give me wrong date like this. '01/01/1970' But I want format and date like this '25/08/2016'.

$today = '24/08/2016';
$nextday = strftime("%d/%m/%Y", strtotime("$today +1 day"));

so please help me how can i do this.advance thanx.

How to increase date by 1 day in php?

asked Aug 24, 2016 at 6:18

3

You can use strtotime.

$your_date = strtotime("1 day", strtotime("2016-08-24"));
$new_date = date("Y-m-d", $your_date);

Hope it will help you.

answered Aug 24, 2016 at 6:21

How to increase date by 1 day in php?

NomanNoman

1,4002 gold badges17 silver badges38 bronze badges

0

If you want to use DateTime:

$today      = '24/08/2016';    
$nextDay    = DateTime::createFromFormat('d/m/Y', $today)
                ->add(new DateInterval('P1D'))
                ->format('d/m/Y');

answered Aug 24, 2016 at 6:26

How to increase date by 1 day in php?

HTMHellHTMHell

5,3215 gold badges35 silver badges75 bronze badges

It's important to note the different interpretation of - and / in the date. If you use a - php will determine it to be DD-MM, if you use a / php will determine it to be MM-DD. So you need to use - instead of /

<?php

$today = '24-08-2016';
echo $nextday = date("d-m-Y", strtotime("$today +1 day"));

?>

answered Aug 24, 2016 at 6:24

How to increase date by 1 day in php?

Mittul ChauhanMittul Chauhan

4071 gold badge6 silver badges18 bronze badges

See below perfect working code

<?php
    echo $startDate = date('Y-m-d H:i:s'); echo "<br/>";
    echo $nextDate = date("Y-m-d H:i:s", strtotime("$startDate +1 day"));
?>

answered Aug 24, 2016 at 6:25

How to increase date by 1 day in php?

Raghbendra NayakRaghbendra Nayak

1,5863 gold badges23 silver badges44 bronze badges

You should replace the / with -

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European** d-m-y format is assumed**.

Reference: http://php.net/manual/en/function.strtotime.php

Try this:

$today = '24/08/2016';
$today = str_replace('/', '-', $today);
$today = date('Y-m-d', strtotime($today));
$nextday = date("d/m/Y", strtotime($today. "+1 day")); // Output: 25/08/2016

answered Aug 24, 2016 at 6:22

How to increase date by 1 day in php?

Please use below code

<?php
  $today = '24/08/2016';
  $today = explode('/',$today);
  $nextday = date('d/m/Y',mktime(0,0,0,$today[1],$today[0]+1,$today[2])));
?>

answered Aug 24, 2016 at 6:22

How to increase date by 1 day in php?

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    Adding days to $Date can be done in many ways. It is very easy to do by using built-in functions like strtotime(), date_add() in PHP.
    Method 1: Using strtotime() Function: The strtotime() Function is used to convert an English textual date-time description to a UNIX timestamp. 
    Syntax: 
     

    strtotime( $EnglishDateTime, $time_now )

    Parameters: This function accepts two optional parameters as mentioned above and described below. 
     

    • $EnglishDateTime: This parameter specifies the English textual date-time description, which represents the date or time to be returned.
    • $time_now: This parameter specifies the timestamp used to calculate the returned value. It is an optional parameter.

    Program: PHP program to add days to $Date in PHP using strtotime() function. 
     

    php

    <?php

    $Date = "2019-05-10";

    echo date('Y-m-d', strtotime($Date. ' + 10 days'));

    ?>

    Method 2: Using date_add() Function: The date_add() function is used to add days, months, years, hours, minutes and seconds.
    Syntax: 
     

    date_add(object, interval);

    Parameters: This function accepts two parameters as mentioned above and described below: 
     

    • Object: It specifies the DateTime object returned by date_create() function.
    • Interval: It specifies the DateInterval object.

    Program: PHP program to add days to $Date in PHP using date_add() function. 
     

    php

    <?php

    $date = date_create("2019-05-10");

    date_add($date, date_interval_create_from_date_string("10 days"));

    echo date_format($date, "Y-m-d");

    ?>


    How do I add 1 day to a date?

    const date = new Date(); date. setDate(date. getDate() + 1); // ✅ 1 Day added console..
    Use the getDate() method to get the day of the month for the given date..
    Use the setDate() method to set the day of the month to the next day..
    The setDate method will add 1 day to the Date object..

    How to add number of days to a date in PHP?

    The date_add() function adds some days, months, years, hours, minutes, and seconds to a date.

    How can I change the date format in PHP?

    To convert the date-time format PHP provides strtotime() and date() function..
    <? php..
    $orgDate = "2019-02-26";.
    $newDate = date("m-d-Y", strtotime($orgDate));.
    echo "New date format is: ". $newDate. " (MM-DD-YYYY)";.

    How to add time and date in PHP?

    php $date=strtotime("tomorrow"); echo date("Y-m-d h:i:sa", $date) . "<br>"; $date=strtotime("next Sunday"); echo date("Y-m-d h:i:sa", $date) . "<br>"; $date=strtotime("+3 Months"); echo date("Y-m-d h:i:sa", $date) .