note 29519 added to ref.datetime
| From: | balin at rack1 dot php dot net | Date: | Sun, 16 Feb 2003 07:23:03 +0000 |
| Subject: | note 29519 added to ref.datetime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44047@lists.php.net to get a copy of this message | ||
this function count days between $start and $end dates in mysql format (yyyy-mm-dd)
if one of paramters is 0000-00-00 will return 0
$start date must be less then $end
<?
//For Count Days
function count_days($start, $end)
{
if( $start != '0000-00-00' and $end != '0000-00-00' )
{
$timestamp_start = strtotime($start);
$timestamp_end = strtotime($end);
if( $timestamp_start >= $timestamp_end ) return 0;
$start_year = date("Y",$timestamp_start);
$end_year = date("Y", $timestamp_end);
$num_days_start = date("z",strtotime($start));
$num_days_end = date("z", strtotime($end));
$num_days = 0;
$i = 0;
if( $end_year > $start_year )
{
while( $i < ( $end_year - $start_year ) )
{
$num_days = $num_days + date("z", strtotime(($start_year +
$i)."-12-31"));
$i++;
}
}
return ( $num_days_end + $num_days ) - $num_days_start;
}
else
{
return 0;
}
}
?>
--
http://www.php.net/manual/en/ref.datetime.php
http://master.php.net/manage/user-notes.php?action=edit+29519
http://master.php.net/manage/user-notes.php?action=delete+29519
http://master.php.net/manage/user-notes.php?action=reject+29519