-1

時間関数time()を使用して、患者の予想待機時間を出力したいと思います。

現在、次のフィールドがあります。

 PatientID   Forename  Surname   Illness   Priority    Waiting Time 

次の計算の現在の時刻を取得するために、time関数をPHPに組み込むにはどうすればよいですか。

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

2 に答える 2

0

データベースでは、関数を使用して時間を節約する必要がありtime()ます。これは、並べ替えなどに適しています。日付をフォーマットで表示したい場合は、date('G:ia', $time);

幸運を。

于 2013-03-21T22:07:37.620 に答える
0

エポック/UNIX時間をデータベースに保存する必要があります。

$the_time = time();

これらのエポック/UNIX時間としてすべての異なるタイムスタンプを保存し、後でそれらを日付に簡単に変換できます。

date( 'G:ia', $the_time );

また、epoch / unix時間を使用して、2つの異なる時間がどれだけ離れているかを簡単に判断できます。

$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 に答える