envexlabs Posted September 16, 2008 Share Posted September 16, 2008 Hey, My last thread wasn't explained very well, and i can't delete it, so i decided to re-word it a it better. I have 2 dates: Last payment: 2008-09-15 Today: 2008-10-02 Next Payment: 2008-10-15 I need to figure out how many days are remaining until next payment, but the overlapping of months is throwing the number off. Any one have an idea, i think i'm using mktime() and date() improperly. Thanks, envex Quote Link to comment https://forums.phpfreaks.com/topic/124511-calculate-days-remaining-for-overlaping-months/ Share on other sites More sharing options...
JonnoTheDev Posted September 16, 2008 Share Posted September 16, 2008 function days_between($fyear, $fmonth, $fday, $tyear, $tmonth, $tday) { return abs((mktime ( 0, 0, 0, $fmonth, $fday, $fyear) - mktime ( 0, 0, 0, $tmonth, $tday, $tyear))/(60*60*24)); } echo days_between(2008, 10, 2, 2008, 10, 15); Quote Link to comment https://forums.phpfreaks.com/topic/124511-calculate-days-remaining-for-overlaping-months/#findComment-642996 Share on other sites More sharing options...
envexlabs Posted September 16, 2008 Author Share Posted September 16, 2008 Thanks! Worked like a charm. One more question: This is what i'm grabbing from the database: Last Pay: 2008-8-09 Today: 2008-09-16 Due On: 2008-9-09 Days Left: 7 (your output) As you can see, the payment is past due but it's showing 7 days past. Could i somehow figure out if it's over the due day and return false? Quote Link to comment https://forums.phpfreaks.com/topic/124511-calculate-days-remaining-for-overlaping-months/#findComment-643008 Share on other sites More sharing options...
JonnoTheDev Posted September 16, 2008 Share Posted September 16, 2008 function days_between($fyear, $fmonth, $fday, $tyear, $tmonth, $tday) { $diff = abs((mktime ( 0, 0, 0, $fmonth, $fday, $fyear) - mktime ( 0, 0, 0, $tmonth, $tday, $tyear))/(60*60*24)); if($diff >= 1) { return false; } return true; } if(!days_between(2008, 10, 2, 2008, 10, 15)) { echo "your payment is overdue"; } Quote Link to comment https://forums.phpfreaks.com/topic/124511-calculate-days-remaining-for-overlaping-months/#findComment-643323 Share on other sites More sharing options...
akitchin Posted September 16, 2008 Share Posted September 16, 2008 if you're grabbing this info from a database, your best bet is to use TO_DAYS(), a MySQL function. there's no reason to use PHP when MySQL can do exactly what you're after. Quote Link to comment https://forums.phpfreaks.com/topic/124511-calculate-days-remaining-for-overlaping-months/#findComment-643337 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.