Increase Days to PHP Current Date()

Increase days to php current Date()

php supports c style date functions. You can add or substract date-periods with English-language style phrases via the strtotime function. examples...

$Today=date('y:m:d');

// add 3 days to date
$NewDate=Date('y:m:d', strtotime('+3 days'));

// subtract 3 days from date
$NewDate=Date('y:m:d', strtotime('-3 days'));

// PHP returns last sunday's date
$NewDate=Date('y:m:d', strtotime('Last Sunday'));

// One week from last sunday
$NewDate=Date('y:m:d', strtotime('+7 days Last Sunday'));

or

<select id="date_list" class="form-control" style="width:100%;">
<?php
$max_dates = 15;
$countDates = 0;
while ($countDates < $max_dates) {
$NewDate=Date('F d, Y', strtotime("+".$countDates." days"));
echo "<option>" . $NewDate . "</option>";
$countDates += 1;
}
?>

add some days to current date in php

You can use strtotime() function to add days to current date. Please see the below :

 <?php
$date =date("Y-m-d");
$day = 5;
$newdate=date('Y-m-d', strtotime("+$day days"));
echo "today is:".$date;
echo "<br> and after 5 days is :".$newdate;
?>

Add 30 days to date

Please try this.

echo date('m/d/Y',strtotime('+30 days',strtotime('05/06/2016'))) . PHP_EOL;

This will return 06/06/2016. Am assuming your initial date was in m/d/Y format. If not, fret not and use this.

echo date('d/m/Y',strtotime('+30 days',strtotime(str_replace('/', '-', '05/06/2016')))) . PHP_EOL;

This will give you the date in d/m/Y format while also assuming your initial date was in d/m/Y format. Returns 05/07/2016

If the input date is going to be in mysql, you can perform this function on mysql directly, like this.

DATE_ADD(due_date, INTERVAL 1 MONTH);

PHP date add 5 year to current date

Try with:

$end = date('Y-m-d', strtotime('+5 years'));

Adding one day to a date

<?php
$stop_date = '2009-09-30 20:24:00';
echo 'date before day adding: ' . $stop_date;
$stop_date = date('Y-m-d H:i:s', strtotime($stop_date . ' +1 day'));
echo 'date after adding 1 day: ' . $stop_date;
?>

For PHP 5.2.0+, you may also do as follows:

$stop_date = new DateTime('2009-09-30 20:24:00');
echo 'date before day adding: ' . $stop_date->format('Y-m-d H:i:s');
$stop_date->modify('+1 day');
echo 'date after adding 1 day: ' . $stop_date->format('Y-m-d H:i:s');

Add number of days to a date

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.

PHP - Add one week to a user defined date

You can try this

$start_date = "2015/03/02";  
$date = strtotime($start_date);
$date = strtotime("+7 day", $date);
echo date('Y/m/d', $date);

adding 1 day to a DATETIME format value

If you want to do this in PHP:

// replace time() with the time stamp you want to add one day to
$startDate = time();
date('Y-m-d H:i:s', strtotime('+1 day', $startDate));

If you want to add the date in MySQL:

-- replace CURRENT_DATE with the date you want to add one day to
SELECT DATE_ADD(CURRENT_DATE, INTERVAL 1 DAY);

Increase current date by 5 days

You could use mktime() using the timestamp.

Something like:

$date = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + 5, date('Y')));

Using strtotime() is faster, but my method still works and is flexible in the event that you need to make lots of modifications. Plus, strtotime() can't handle ambiguous dates.

Edit

If you have to add 5 days to an already existing date string in the format YYYY-MM-DD, then you could split it into an array and use those parts with mktime().

$parts = explode('-', $date);
$datePlusFive = date(
'Y-m-d',
mktime(0, 0, 0, $parts[1], $parts[2] + 5, $parts[0])
// ^ Month ^ Day + 5 ^ Year
);


Related Topics



Leave a reply



Submit