Login or Register Now   Email:  Password:   

Days Between Two Dates

Here is a function that will return the number of days between two dates. The to and the from dates must be unix timestamps and will return the number of days between them. An optional third parameter is provided to switch on rounding of the days to two decimal places.


<?php

 
/*
  *
  * @caluculate days between dates
  *
  * @param int $from The date from
  *
  * @param int $to the date to
  *
  * @param bool $round Turn rounding on/off
  *
  * @return float
  *
  */
 
function daysTo($from$to$round=true)
 {
    
$diff $to-$from;
    
$days $diff/86400;
    return 
$round==true floor($days) : round($days,2);
 }


 
/*** example usage ***/
 
$from 'jan 10 2008';

 
$to time();

 
$from strtotime($from);

 echo 
daysTo($from$to)."<br />";

 echo 
daysTo($from$tofalse);

?>