inspireddesign Posted August 10, 2009 Share Posted August 10, 2009 Hello all, This is strange. I have this working when I force the dates in the function. I can pass the $today value just fine and the num_days returns correctly the way its written now. However, if the function is used on a date array pulled from the database, it displays in decimals. The data that is pulled in from the database is in the correct format when echoed but... still the decimals are returned. Any ideas? <? function daysPastDue($pastDate) { $today = date('Y-m-d'); $num_days = (strtotime("2009-07-09") - strtotime($today)) / (60 * 60 * 24); return $num_days; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169650-solved-days-between-to-dates/ Share on other sites More sharing options...
kickstart Posted August 10, 2009 Share Posted August 10, 2009 Hi Is $pastDate a date or a full date time. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/169650-solved-days-between-to-dates/#findComment-895005 Share on other sites More sharing options...
inspireddesign Posted August 10, 2009 Author Share Posted August 10, 2009 Just a date Quote Link to comment https://forums.phpfreaks.com/topic/169650-solved-days-between-to-dates/#findComment-895011 Share on other sites More sharing options...
kickstart Posted August 10, 2009 Share Posted August 10, 2009 Hi What is the decimal date you are getting? By the way, think strtotime expects to get a date in US format (mdY format), but attempts to translate other formats. It might have got it wrong. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/169650-solved-days-between-to-dates/#findComment-895031 Share on other sites More sharing options...
inspireddesign Posted August 10, 2009 Author Share Posted August 10, 2009 When I return the date from the database array it's in the Y,m,d format (2009-09-10). The date decimal looks something like: -235.958333333 (2008-12-17), -233.958333333 (2008-12-19) The return days are from today's date. It looks like the days aren't getting rounded? Actually, that's exactly what's happening. I tested this by changing the date 9 days from today and it works fine. The funny thing is, why after 154 days does it stop rounding the numbers? Thanks for the help so far. Quote Link to comment https://forums.phpfreaks.com/topic/169650-solved-days-between-to-dates/#findComment-895036 Share on other sites More sharing options...
kickstart Posted August 10, 2009 Share Posted August 10, 2009 Hi Quick play and one thing that does seem to trigger a decimal (as well as a warning) is if you pass and array to the function rather than an array member. Could you post the code that calls the function. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/169650-solved-days-between-to-dates/#findComment-895052 Share on other sites More sharing options...
inspireddesign Posted August 10, 2009 Author Share Posted August 10, 2009 I figured it out... It was working fine. I'm now returning the number rounded. Thanks Keith for your help. <? function daysPastDue($pastDate) { $today = date('Y-m-d'); $num_days = (strtotime("2009-07-09") - strtotime($today)) / (60 * 60 * 24); // return rounded number return round($num_days); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169650-solved-days-between-to-dates/#findComment-895054 Share on other sites More sharing options...
nankoweap Posted August 10, 2009 Share Posted August 10, 2009 have you considered letting the database perform the calculations? Quote Link to comment https://forums.phpfreaks.com/topic/169650-solved-days-between-to-dates/#findComment-895090 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.