Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP DateTime Functions

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?

like image 588
cdub Avatar asked Dec 02 '11 06:12

cdub


1 Answers

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.

like image 72
stefgosselin Avatar answered Sep 24 '22 02:09

stefgosselin