// +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ // | Copyright (c) 2003 The individual | // +----------------------------------------------------------------------+ // |It agrees without being passing through the very person and it is | // |conceited secretly using the after result. | // +----------------------------------------------------------------------+ // | Authors: Original Author Allan Kent | // | Editing Dandelion | // +----------------------------------------------------------------------+
/** * @Purpose: * It returns to the time interval during two dates. * @Method Name: DateDiff(). * @Parameter: string $interval -->The time interval character string numerical formula. * w -->Weekday * d -->Day * h -->Hour * n -->Minute * s -->Second * string $date1 -->It represents as time() a form in the time of the first date. * string $date2 -->It represents as time() a form in the time of the second date. * @Return: string $retval -->Return a new as time() a form in the time of the date. * @See: string bcdiv(string left operand,string right operand, int [scale]). */ function DateDiff($interval, $date1, $date2) {
// @See: It gets the number of the seconds in the one of the 2nd period day interval. $time_difference = $date2 - $date1; switch ($interval) {
case "w": $retval = bcdiv($time_difference, 604800); break; case "d": $retval = bcdiv($time_difference, 86400); break; case "h": $retval = bcdiv($time_difference, 3600); break; case "n": $retval = bcdiv($time_difference, 60); break; case "s": $retval = $time_difference; break; }
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The individual |
// +----------------------------------------------------------------------+
// |It agrees without being passing through the very person and it is |
// |conceited secretly using the after result. |
// +----------------------------------------------------------------------+
// | Authors: Original Author Allan Kent |
// | Editing Dandelion |
// +----------------------------------------------------------------------+
/**
* @Purpose:
* It returns to the time interval during two dates.
* @Method Name: DateDiff().
* @Parameter: string $interval -->The time interval character string numerical formula.
* w -->Weekday
* d -->Day
* h -->Hour
* n -->Minute
* s -->Second
* string $date1 -->It represents as time() a form in the time of the first date.
* string $date2 -->It represents as time() a form in the time of the second date.
* @Return: string $retval -->Return a new as time() a form in the time of the date.
* @See: string bcdiv(string left operand,string right operand, int [scale]).
*/ function DateDiff($interval, $date1, $date2) {
// @See: It gets the number of the seconds in the one of the 2nd period day interval.
$time_difference = $date2 - $date1;
switch ($interval) {
case "w": $retval = bcdiv($time_difference, 604800); break;
case "d": $retval = bcdiv($time_difference, 86400); break;
case "h": $retval = bcdiv($time_difference, 3600); break;
case "n": $retval = bcdiv($time_difference, 60); break;
case "s": $retval = $time_difference; break;
}
return $retval;} ?>
在线等
strtotime("2003-3-12 8:10:00")
echo (strtotime("2003-03-12 9:05:36")-strtotime("03/12/2003 9:04AM"))/3600; // out 0.026666666666667
请指点
在线等
2、做日期比较可在sql里进行,不必取出来再做。DateDiff是mssql的函数,Successful(火烈鸟) 给出的是php的仿DateDiff函数,其实mysql有自己的日期时间函数