ajoo Posted December 11, 2013 Share Posted December 11, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284709-difference-between-2-dates-in-terms-of-days/ Share on other sites More sharing options...
dalecosp Posted December 11, 2013 Share Posted December 11, 2013 (edited) 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? Edited December 11, 2013 by dalecosp Quote Link to comment https://forums.phpfreaks.com/topic/284709-difference-between-2-dates-in-terms-of-days/#findComment-1462100 Share on other sites More sharing options...
Barand Posted December 11, 2013 Share Posted December 11, 2013 (edited) 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 Edited December 11, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/284709-difference-between-2-dates-in-terms-of-days/#findComment-1462118 Share on other sites More sharing options...
grissom Posted December 11, 2013 Share Posted December 11, 2013 There is a bug on windows platforms !! https://bugs.php.net/bug.php?id=51184 Quote Link to comment https://forums.phpfreaks.com/topic/284709-difference-between-2-dates-in-terms-of-days/#findComment-1462122 Share on other sites More sharing options...
Barand Posted December 11, 2013 Share Posted December 11, 2013 I've never had that problem. The above code I posted gave 4 days (OS = Windows 7, PHP version = 5.3.10) Quote Link to comment https://forums.phpfreaks.com/topic/284709-difference-between-2-dates-in-terms-of-days/#findComment-1462123 Share on other sites More sharing options...
grissom Posted December 11, 2013 Share Posted December 11, 2013 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 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 Quote Link to comment https://forums.phpfreaks.com/topic/284709-difference-between-2-dates-in-terms-of-days/#findComment-1462126 Share on other sites More sharing options...
ajoo Posted December 12, 2013 Author Share Posted December 12, 2013 Thanks guys ! Well I too came across the fact that its a bug. Like I said it worked just fine on phpfiddle but not on my local host. Taking a wayaround. Thanks all. Quote Link to comment https://forums.phpfreaks.com/topic/284709-difference-between-2-dates-in-terms-of-days/#findComment-1462156 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.