Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add number of days to a date

Tags:

date

php

People also ask

How do you add a number of days to a date?

Press Ctrl+1 to launch the Format Cells dialog, and click the Number tab. Under Category, click Date, select the date format you want, and then click OK. The value in each of the cells should appear as a date instead of a serial number.

How do I add 60 days to a date in Excel?

Type '=' and select the first cell of the column containing the dates you want to add days to (cell A2). Next, type '+' followed by the number of days you want to add.

How do I add 70 days to a date in Excel?

In a first cell (for example A1), enter the date: 01/03/2016. In a second cell (for example B1), enter the number of days you want to add: 25. In a third cell (for example C1), type in the formula: =SUM (A1+B1) Excel will automatically compute the resulting date and the result will be 01/28/2016.


This should be

echo date('Y-m-d', strtotime("+30 days"));

strtotime

expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied.

while date

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.

See the manual pages for

  • http://www.php.net/manual/en/function.strtotime.php
  • http://www.php.net/manual/en/function.date.php

and their function signatures.


This one might be good

function addDayswithdate($date,$days){

    $date = strtotime("+".$days." days", strtotime($date));
    return  date("Y-m-d", $date);

}

$date = new DateTime();
$date->modify('+1 week');
print $date->format('Y-m-d H:i:s');

or print date('Y-m-d H:i:s', mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 7, date("Y"));


$today=date('d-m-Y');
$next_date= date('d-m-Y', strtotime($today. ' + 90 days'));
echo $next_date;

You can add like this as well, if you want the date 5 days from a specific date :

You have a variable with a date like this (gotten from an input or DB or just hard coded):

$today = "2015-06-15"; // Or can put $today = date ("Y-m-d");

$fiveDays = date ("Y-m-d", strtotime ($today ."+5 days"));

echo $fiveDays; // Will output 2015-06-20