实例
例子 1
使用如下 SELECT 语句:
SELECT DATEDIFF('2008-12-30','2008-12-29') AS DiffDate结果:
DiffDate
1
例子 2
使用如下 SELECT 语句:
SELECT DATEDIFF('2008-12-29','2008-12-30') AS DiffDate结果:
DiffDate
-1
例子 1
使用如下 SELECT 语句:
SELECT DATEDIFF('2008-12-30','2008-12-29') AS DiffDate结果:
DiffDate
1
例子 2
使用如下 SELECT 语句:
SELECT DATEDIFF('2008-12-29','2008-12-30') AS DiffDate结果:
DiffDate
-1
如题,我在BugHistory.tpl中
{$HistoryInfo.UserName}
后面增加了
{if $HistoryInfo.Action !="Open"}
历时: (UNIX_TIMESTAMP{$HistoryInfo.ActionDate} - UNIX_TIMESTAMP{$BugInfo.OpenedDate})/60 分钟
{else}
{/if}
但显示结果只能出来函数值,出不了计算结果,要怎么实现?
UNIX_TIMESTAMP是mysql的函数。无法嵌在这里使用。估计你要写在PHP
下面是我用的一段函数,跟你的需求差不多(函数是php手册里面提供的^_^):
function date_diff($start_date, $end_date, $returntype="d")
{
if ($returntype == "s")
$calc = 1;
if ($returntype == "m")
$calc = 60;
if ($returntype == "h")
$calc = (60*60);
if ($returntype == "d")
$calc = (60*60*24);
$_d1 = explode("-", $start_date);
$y1 = $_d1[0];
$m1 = $_d1[1];
$d1 = $_d1[2];
$_d2 = explode("-", $end_date);
$y2 = $_d2[0];
$m2 = $_d2[1];
$d2 = $_d2[2];
if (($y1 < 1970 || $y1 > 2037) || ($y2 < 1970 || $y2 > 2037))
{
return 0;
} else
{
$today_stamp = mktime(0,0,0,$m1,$d1,$y1);
$end_date_stamp = mktime(0,0,0,$m2,$d2,$y2);
$difference = round(($end_date_stamp-$today_stamp)/$calc);
return $difference;
}
}
$PassDate = date_diff($BugInfo[$_GET["BugID"]]["ClosedDate"],date('Y-m-d'), "d");
{
if ($returntype == "s")
$calc = 1;
if ($returntype == "m")
$calc = 60;
if ($returntype == "h")
$calc = (60*60);
if ($returntype == "d")
$calc = (60*60*24);
$_d1 = explode("-", $start_date);
$y1 = $_d1[0];
$m1 = $_d1[1];
$d1 = $_d1[2];
$_d2 = explode("-", $end_date);
$y2 = $_d2[0];
$m2 = $_d2[1];
$d2 = $_d2[2];
if (($y1 < 1970 || $y1 > 2037) || ($y2 < 1970 || $y2 > 2037))
{
return 0;
} else
{
$today_stamp = mktime(0,0,0,$m1,$d1,$y1);
$end_date_stamp = mktime(0,0,0,$m2,$d2,$y2);
$difference = round(($end_date_stamp-$today_stamp)/$calc);
return $difference;
}
}
$PassDate = date_diff($BugInfo[$_GET["BugID"]]["ClosedDate"],date('Y-m-d'), "d");
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/3315/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表