-1

我想使用时间函数 time() 来输出患者的预期等待时间。

我目前有以下领域;

 PatientID   Forename  Surname   Illness   Priority    Waiting Time 

如何将时间函数合并到 PHP 中以获取当前时间以进行以下计算;

 waiting time would be (the clock time - the arrival time) 
4

2 回答 2

0

在数据库中,您应该使用time()函数节省时间。这有利于排序等等。当您想查看带有格式的日期时,只需使用 withdate('G:ia', $time);

祝你好运。

于 2013-03-21T22:07:37.620 回答
0

您应该将纪元/unix时间存储在数据库中:

$the_time = time();

您可以将所有不同的时间戳存储为这些纪元/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' );

}
于 2013-03-21T22:09:45.080 回答