Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

php datetimemodify adding and subtracting months

php datetimemodify adding and subtracting months  using -'php,datetime,date'

I've been working a lot with the DateTime class and recently ran into what I thought was a bug when adding months.  After a bit of research, it appears that it wasn't a bug, but instead working as intended.  According to the documentation found here:

  Example #2 Beware when adding or
  subtracting months

$date = new DateTime('2000-12-31');

$date->modify('+1 month');
echo $date->format('Y-m-d') . "\n";

$date->modify('+1 month');
echo $date->format('Y-m-d') . "\n";

The above example will output:

Can anyone justify why this isn't considered a bug?

Furthermore does anyone have any elegant solutions to correct the issue and make it so +1 month will work as expected instead of as intended?

asked Sep 29, 2015 by vibhorsingh
0 votes

Related Hot Questions

Government Jobs Opening