簡體   English   中英

在DATETIME增加分鍾

[英]Adding minutes to DATETIME

我試圖在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()))';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM