Posted: Fri Apr 01, 2005 5:39 pm
lose the single quotes around your variables.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
function makeTimestamp( $date )
{
static $months = array( 1 => 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' );
$fixed = preg_replace('#^\s*(\d{1,2})\s*(ї-/\.])\s*(\d{1,2})\s*\\2\s*(\d{2,4})\s*$#e', 'sprintf(\'%02d-%s-%04d\', intval(\'\\1\'), $monthsїintval(\'\\3\')], (strlen(\'\\4\') < 4 ? (intval(\'\\4\') < 70 ? 2000 : 1900) : 0) + intval(\'\\4\') )', $date);
return strtotime($fixed);
}
function toDays( $timestamp )
{
return intval(intval($timestamp) / (24 * 60 * 60));
}
function dateDiff( $date1, $date2 )
{
$date1 = toDays(makeTimestamp( $date1 ));
$date2 = toDays(makeTimestamp( $date2 ));
return abs($date1 - $date2);
}
echo dateDiff( '1-3-2005', '05-03-2005' );
?>