我试图获取当前日期和小时之间的日,小时和分钟以及MySQL和PHP中的DATETIME字段。我需要获得以下信息:
x天,x小时和x分钟完成。
SELECT TIMESTAMPDIFF(DAY,NOW(),FECHA_FIN) AS DAY,
TIMESTAMPDIFF(HOUR,NOW(),FECHA_FIN)-TIMESTAMPDIFF(DAY,NOW(),FECHA_FIN)*24 AS HOUR,
TIMESTAMPDIFF(MINUTE,NOW(),FECHA_FIN)-TIMESTAMPDIFF(HOUR,NOW(),FECHA_FIN)*60 AS MINUTE FROM ARTICULOS
答案 0 :(得分:0)
<?php
$dbc = [connection details here];
$result = mysqli_query($dbc, "SELECT FETCHA_FIN FROM ARTICULOS;");
while($row = mysqli_fetch_row($result))
{
$dbtime = $row[0];
$now = date("d/m/Y h:i:s");
$difference = $now-$dbtime;
echo "Time to complete: " . date("h", $difference) . " hours, " . date("i", $difference) . " minutes and " . date("s", $difference) . " seconds.";
}
?>
不幸的是,我没有时间测试上面的代码,但它应该可以正常工作,因为我之前使用过类似的代码。
答案 1 :(得分:0)
SELECT FLOOR(TIMESTAMPDIFF(MINUTE, NOW(), FECHA_FIN) / 1440) as Days
, FLOOR(TIMESTAMPDIFF(MINUTE, NOW(), FECHA_FIN) % 1440 / 60) as Hours
, TIMESTAMPDIFF(MINUTE, NOW(), FECHA_FIN) % 60 as Minutes
FROM ARTICULOS;