Page 2 of 2

Posted: Fri Apr 01, 2005 5:39 pm
by Burrito
lose the single quotes around your variables.

Posted: Fri Apr 01, 2005 5:39 pm
by feyd
juice, did you get the memo about the TPS repor -- I mean -- Posting Code Guidelines?

'05' for a year is 1905 to the functions, which is an "invalid" date. You specifically said in your original post the year is coming across 2004.. oh well..

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' );
 
?>
that should allow for lower digits on year..


sending the dates to the function correctly, helps too. :)

Posted: Fri Apr 01, 2005 6:37 pm
by juice
the output for year is 2005 and not 05. sorry if confused you. ill try out loosing quotes but i think i tried that already

Posted: Fri Apr 01, 2005 7:26 pm
by juice
that worked a treat so it did.thank you. but have 1 problem but wont post it now. have enough for tonite.ill try and figure it out 2morow