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?

1
  • mmm... can you add the "mess" code? Commented Dec 2, 2011 at 6:42

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

awesome, its always only the next operation that breaks, i've had this bug for awhile
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)
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.