5

I have the following code fragment:

$now = '2011-12-01 22:32:33';
$datetime = '2011-12-01 00:07:27';  


$nowObj = new DateTime($now);
$datetimeObj = new DateTime($datetime);

$diff = $datetimeObj->diff($nowObj); //leaving this in screws up the next line

number_format(1134); //this becomes NaN

When I am running through this code and leave the $diff = ... line in, it messes with other numbers and math that I do later in the code. For instance, my number_format(1134); later on becomes NaN. I am using a XAMPP stack with PHP 5.3.1. Is this a bug?

j0k
  • 22,600
  • 28
  • 79
  • 90
cdub
  • 24,555
  • 57
  • 174
  • 303

2 Answers2

5

Could this be related, hmm ...

If you are on windows, I would make sure time zone settings are set correctly. The comments on php.net point out a couple of quirks and buggy behavior under windows, maybe seriously consider using an alternate method for diffing your dates if issues persist.

Stephane Gosselin
  • 9,030
  • 5
  • 42
  • 65
  • awesome, its always only the next operation that breaks, i've had this bug for awhile – cdub Dec 02 '11 at 06:53
  • No problem, they point to a bugfix in that post, if the fix does not work or your php version is more recent, please consider posting back on that board your finding, or re-opening an issue on this? It would help make php better. Or, at least the date object, maybe. :o) – Stephane Gosselin Dec 02 '11 at 11:11
0

It seem a locale problem. hev you set the timezone in php.ini?

[Date]
date.timezone = Europe/Rome

Europe/Rome is my timezone ;)

or you can also add

ini_set("date.timezone","Europe/Rome");

in your code

Ivan Buttinoni
  • 4,110
  • 1
  • 24
  • 44