Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add six months in php

Tags:

date

php

datetime

I'm trying to get the month, six months out from the current date.

I've tried using:

date('d', strtotime('+6 month', time()));

But it doesn't seem to work, always returns 01. Is there a better way to do this?

Thank you!

like image 333
dzm Avatar asked Dec 20 '12 16:12

dzm


People also ask

How to add months in date in PHP?

Sample Solution: PHP Code: <? php $dt = strtotime("2012-12-21"); echo date("Y-m-d", strtotime("+1 month", $dt)).

How to add month to current month in PHP?

Example 2: PHP Add Months to Current Date$newDate = date('Y-m-d', strtotime(' + 4 months')); echo $newDate; ?>

Which function can be used to change the date from current month to three months previous?

You can use the EDATE function to quickly add or subtract months from a date. The EDATE function requires two arguments: the start date and the number of months that you want to add or subtract. To subtract months, enter a negative number as the second argument. For example, =EDATE("9/15/19",-5) returns 4/15/19.


1 Answers

If you still wanted to use strtotime and the date function as opposed to a DateTime() object, the following would work:

date('d', strtotime('+6 months'));
like image 107
Dan Greaves Avatar answered Sep 22 '22 15:09

Dan Greaves