PHP Date Add 5 Year to Current Date

PHP date add 5 year to current date

Try with:

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

add one year to datetime with php

strtotime() is the function you're looking for:

$data['user']['seal_data'] = date('Y-m-d H:i:s', strtotime('+1 year', strtotime($data['user']['time'])));

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;
?>

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 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);

$date + 1 year?

To add one year to todays date use the following:

$oneYearOn = date('Y-m-d',strtotime(date("Y-m-d", mktime()) . " + 365 day"));

For the other examples you must initialize $StartingDate with a timestamp value
for example:

$StartingDate = mktime();  // todays date as a timestamp

Try this

$newEndingDate = date("Y-m-d", strtotime(date("Y-m-d", strtotime($StaringDate)) . " + 365 day"));

or

$newEndingDate = date("Y-m-d", strtotime(date("Y-m-d", strtotime($StaringDate)) . " + 1 year"));

How do I use PHP to get the current year?

You can use either date or strftime. In this case I'd say it doesn't matter as a year is a year, no matter what (unless there's a locale that formats the year differently?)

For example:

<?php echo date("Y"); ?>

On a side note, when formatting dates in PHP it matters when you want to format your date in a different locale than your default. If so, you have to use setlocale and strftime. According to the php manual on date:

To format dates in other languages,
you should use the setlocale() and
strftime() functions instead of
date().

From this point of view, I think it would be best to use strftime as much as possible, if you even have a remote possibility of having to localize your application. If that's not an issue, pick the one you like best.

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
);

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);


Related Topics



Leave a reply



Submit