Jump to content

Recommended Posts

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

?>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/169650-solved-days-between-to-dates/
Share on other sites

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.

 

 

I figured it out... It was working fine.  I'm now returning the number rounded.  :facewall:  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);


}

?>

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.