我试图在SQL表中的当前时间上添加一定的分钟数。为此,我尝试了DATEADD SQL函数:
$insert = 'INSERT INTO Waiting_list(
ID_Patient,
Arrival_Time,
Classification,
Target_Time)
VALUES (
"'.$_SESSION['id'].'",
NOW(),
"'.$_SESSION['classification'].'",
DATEADD(MINUTE, @'.$waitingtime.', @NOW()))';
Target_Time列的类型为DATETIME
尽管如此,我在"())"附近收到了一个SQL错误。NOW()
不能与DATEADD
一起工作吗?
在MYSQL中,您应该使用date_add:
date_add(now(), interval waitingtime MINUTE)
sqlfiddle演示
看起来你可能在使用SQL-SERVER?在这种情况下,试试这个:
$insert = 'INSERT INTO Waiting_list(
ID_Patient,
Arrival_Time,
Classification,
Target_Time)
VALUES (
"'.$_SESSION['id'].'",
getdate(),
"'.$_SESSION['classification'].'",
DATEADD(MINUTE, @'.$waitingtime.', getdate()))';