Jump to content

Today + 1 Month


SkyRanger

Recommended Posts

I am having a problem with a date + month.

 

This is the code:

 

date('Y-m-d', strtotime("+1 month"))

 

The output is: 2013-03-02

 

How would i get it just to go to the last day of the next month if there is only 28 or 30 days of the next month?

 

Not sure how to go about getting what I need:

 

ie:

today is 2013-30-01 add month 2013-28-02

or

today is 2013-28-03 add month 2013-03-31

or

today is 2013-02-16 add month 2013-03-16

 

Is what I need possible?

Link to comment
https://forums.phpfreaks.com/topic/273840-today-1-month/
Share on other sites

Or you could use the relative date/time formats to their full potential:

php > echo date ("Y-m-d", strtotime ("last day of previous month"));
2012-12-31
php > echo date ("Y-m-d", strtotime ("last day of next month"));
2013-02-28

 

As a bonus, you can also use the ± annotations in that format:

php > echo date ("Y-m-d", strtotime ("last day of -2 month"));
2012-11-30

Link to comment
https://forums.phpfreaks.com/topic/273840-today-1-month/#findComment-1409232
Share on other sites

$today = '2013-01-31';

$nextDate = date('Y-m-d', min(strtotime("$today + 1 month"), strtotime('last day of next month')));

echo $nextDate;

 

The above will add a month but set the data to the last day of the next month if necessary.

Link to comment
https://forums.phpfreaks.com/topic/273840-today-1-month/#findComment-1409278
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.