dongxikuo5171 2014-02-10 14:12
浏览 12
已采纳

更改MySQL查询以在SQL Server中工作

I have a query that was originally written for MySQL that writes a timestamp to a record. The query adds 15 minutes to the timestamp, based on the time the query is run.

$query = $con->prepare("UPDATE TableName SET     
LockExpiryTime=ADDTIME(NOW(),'00:15:00'),LockKey=:lockkey
WHERE NOW() > LockExpiryTime AND formID = :formid");
$data = array('lockkey'=>$_SESSION['LockKey'],'formid'=>$_SESSION['formId']);
$query->execute($data);

I know that NOW() is not used in SQL Server, so I'm wondering how I can reconfigure this query to work in it and write the timestamp to a timestamp field. Or would datetime be better in this case?

EDIT: I should explain what this is used for. When the user logs into a form, a lock key and expiration time are generated. The lock lasts fifteen minutes. When the user logs out, both the key and expiry time are reset.

  • 写回答

1条回答 默认 最新

  • duandi8544 2014-02-10 14:18
    关注

    You can use this DATEADD(MINUTE, 15, getdate()) in SQL Server,
    instead of ADDTIME(NOW(), '00:15:00') which you used in MySQL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳