Jump to content

difference between 2 dates in terms of days


ajoo

Recommended Posts

Hi to all !

 

While i await some reply to my earlier query, here's another one - a simpler one perhaps but it has me baffled.

 The following is the code I tested on phpfiddle and it works great. Gives the correct time difference in  days. 

<?php
$date1 =date_create("2013-12-07");
$date2 = date("Y-m-d");
$date2 = date_create("$date2");
echo "<br>";
$Gap = date_diff($date1, $date2);
echo $Gap->format("%a days");
?>

However when i actually implement it on my localhost running version 5.3 of php i get the difference as a multiple of 6015. So if there is a 1 day difference, instead of getting 1, i get 6015. for 3 days i got 18045 which is 6015 * 3. I have tried but i am unable to figure it out.  Any suggestions anyone. 

 

Thanks.

It works fine here.

 

Have you done a var_dump at each stage of processing to see if something's funky?

 

<?php
 
/* Uncomment each commented line in turn and see what's up. */
 
$date1 =date_create("2013-12-07");
//var_dump($date1);exit;
$date2 = date("Y-m-d");
$date2 = date_create("$date2");
//var_dump($date2);exit;
echo "<br>";
$Gap = date_diff($date1, $date2);
//var_dump($Gap);exit;
echo $Gap->format("%a days");

 

Also, what system are you on?

You have some redundant code - what does this give?

$date1 = new DateTime("2013-12-07");
$date2 = new DateTime();
echo "<br>";
$Gap = date_diff($date1, $date2);
echo $Gap->format("%a") . ' days';

edit: BTW it isn't a MySQL problem - moving

From the bugs webpage I quoted, I found this at the bottom :

 

"it's a bug affecting VC6 builds only. If you are affected just get VC9 builds from http://windows.php.net/download/ - you will also most likely need a VC9 or VC10 build of Apache from http://www.apachelounge.com/download/

VC6 is very old, outdated and not supported anymore, it's easy enough and free to upgrade to newer builds"

 

So it looks like it affects some builds and not others  :confused:    It's not a function I use myself, I use my own version of the function which I poached off the php website a loooong time ago  ;D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.