我想使用时间函数time()来输出患者的预期等待时间。
我目前有以下字段;
PatientID Forename Surname Illness Priority Waiting Time
如何将时间函数合并到PHP中以获取以下计算的当前时间;
waiting time would be (the clock time - the arrival time)
答案 0 :(得分:0)
在数据库中,您应该使用time()
功能节省时间。这对排序和其他更好。
如果您想查看格式的日期,请使用date('G:ia', $time);
答案 1 :(得分:0)
您应该将epoch/unix时间存储在数据库中:
$the_time = time();
您可以将所有不同的时间戳存储为epoch/unix次,然后轻松将其转换为日期:
date( 'G:ia', $the_time );
您还可以使用epoch/unix次来轻松确定两个不同时间之间的距离:
$the_time_1 = "1363903644";
$the_time_2 = "1363900644";
$time_diff = $the_time_1 - $the_time_2;
$hours = $time_diff / 3600; // 60 * 60 = number of seconds in an hour
echo $hours . ' hours';
回应您处理等候时间的功能请求:
$the_time_1 = "1363903644";
$the_time_2 = "1362900644";
echo waiting_time( $the_time_1, $the_time_2 );
function waiting_time( $time_1, $time_2 ) {
$time_diff = $time_1 - $time_2;
$days = floor( $time_diff / 86400 ); // 60 * 60 * 24 = number of seconds in a day
$time_diff -= $days * 86400;
$hours = floor( $time_diff / 3600 ); // 60 * 60 = number of seconds in a hour
$time_diff -= $hours * 3600;
$mins = floor( $time_diff / 60 ); // 60 = number of seconds in a minute
return( $days . ' days, ' . $hours . ' hours, ' . $mins . ' minutes' );
}