Extend the time functions in PHP DateDiff and DateAdd
function DateDiff ($part, $begin, $end) {$diff = Strtotime ($end)-Strtotime ($begin); switch ($part) {case "Y": $retval = Bcdiv ($diff, (60 * 60 * 24 * 365));
Break Case "M": $retval = Bcdiv ($diff, (60 * 60 * 24 * 30));
Break Case "W": $retval = Bcdiv ($diff, (60 * 60 * 24 * 7));
Break Case "D": $retval = Bcdiv ($diff, (60 * 60 * 24));
Break Case "h": $retval = Bcdiv ($diff, (60 * 60));
Break Case "n": $retval = Bcdiv ($diff, 60);
Break Case "s": $retval = $diff;
Break
return $retval; function DateAdd ($part, $number, $date) {$date _array = getdate (Strtotime ($date)); $hor = $date _array["hours"]; $min =
$date _array["Minutes"];
$sec = $date _array["seconds"];
$mon = $date _array["Mon"];
$day = $date _array["Mday"];
$yar = $date _array["year"]; Switch ($part) {case "Y": $yar + = $number; break, Case "Q": $mon + + ($number * 3); break; case "M": $mon + = $number;
; Case "W": $day + + ($number * 7);
Break Case "D": $day + + $number;
Break Case "H": $hor + + $number;
Break Case "n": $min + + $number;
Break Case "s": $sec + + $number;
Break
Return Date ("Y-m-d h:i:s", Mktime ($hor, $min, $sec, $mon, $day, $yar)); Function DateAdd ($part, $n, $date) {switch ($part) {case ' y ': $val = Date ("y-m-d h:i:s", Strtotime ($date. "+ $n Year") );
Break Case "M": $val = Date ("y-m-d h:i:s", Strtotime ($date. "+ $n Month"));
Break Case "W": $val = Date ("y-m-d h:i:s", Strtotime ($date. "+ $n Week"));
Break Case "D": $val = Date ("y-m-d h:i:s", Strtotime ($date. "+ $n Day"));
Break Case "h": $val = Date ("y-m-d h:i:s", Strtotime ($date. "+ $n Hour"));
Break Case "n": $val = Date ("y-m-d h:i:s", Strtotime ($date. "+ $n Minute"));
Break Case "s": $val = Date ("y-m-d h:i:s", Strtotime ($date. "+ $n Second"));
Break
return $val; }