Jump to content

Calculate days remaining for overlaping months


envexlabs

Recommended Posts

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

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);

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?

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";
}

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.