Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.