我有一个数据库表,其中包含一个名为“lastfed”的时间戳列。
有人知道如何用当前时间减去例如1小时来更新该列吗?
$query = $db->prepare("UPDATE test SET fullness = $newFullness, lastfed = CURRENT_TIME WHERE id = ?");
答案 0 :(得分:4)
UPDATE test
SET fullness = $newFullness,
lastfed = date_sub(now(), INTERVAL 1 HOUR)
WHERE id = ?
答案 1 :(得分:0)
UPDATE test
SET fullness = $newFullness, lastfed = SUBDATE(CURDATE(), INTERVAL 1 HOUR) WHERE id = ?