I have problem with PHP DateDiff, i dont understand why each timezone returns different results, for example in this case Prague return 0 month, and US return 1 month.
What do this difference and how i return 1 month (instead 30 days, when i adding 1 month) as expected?
code Europe/Prague:
date_default_timezone_set("Europe/Prague");
$from = new \DateTimeImmutable('2016-09-01');
$to = $from->add(new \DateInterval('P1M'));
var_dump($from);
var_dump($to);
var_dump($from->diff($to)->m);
var_dump($from->diff($to)->d);
result Europe/Prague:
object(DateTimeImmutable)#1 (3) {
["date"]=>
string(26) "2016-09-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Prague"
}
object(DateTimeImmutable)#3 (3) {
["date"]=>
string(26) "2016-10-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Prague"
}
int(0)
int(30)
--
code US/Pacific:
date_default_timezone_set("US/Pacific");
$from = new \DateTimeImmutable('2016-09-01');
$to = $from->add(new \DateInterval('P1M'));
var_dump($from);
var_dump($to);
var_dump($from->diff($to)->m);
var_dump($from->diff($to)->d);
result US/Pacific:
object(DateTimeImmutable)#2 (3) {
["date"]=>
string(26) "2016-09-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(10) "US/Pacific"
}
object(DateTimeImmutable)#4 (3) {
["date"]=>
string(26) "2016-10-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(10) "US/Pacific"
}
int(1)
int(0)