Get days between two dates with PHP
Free Scripts :: PHP :: Date and Time :: Get days between two dates with PHP
Author: Salman Javaid
Website: http://www.salman.be
Website: http://www.salman.be
- How to get number of days between two dates.
- Calculate total dayes between two dates.
Function accepts two date parameters and returns the total number of dates between them.
Function:
function count_days( $a, $b ) {
$gd_a = getdate( $a );
$gd_b = getdate( $b );
$a_new = mktime( 12, 0, 0, $gd_a['mon'], $gd_a['mday'], $gd_a['year'] );
$b_new = mktime( 12, 0, 0, $gd_b['mon'], $gd_b['mday'], $gd_b['year'] );
return round( abs( $a_new - $b_new ) / 86400 );
}
?>
Calling The Function:
$date1 = strtotime('2010/04/07');
$date2 = strtotime('2010/04/17');
$total_days = count_days($date1,$date2);
?>
Output:
10 Days




