php 如何使用 NOW() 更新 SQL 日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11064775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to update SQL date using NOW()
提问by CarlTaylor1989
Basically I have a simple login form. In the database I have a 'last_logged' column and would like to update it with the current date and time every time someone logs in.
基本上我有一个简单的登录表单。在数据库中,我有一个“last_logged”列,并且每次有人登录时都想用当前日期和时间更新它。
I currently have this query:
我目前有这个查询:
UPDATE users SET last_logged = "NOW()" WHERE id = 1
But it doesn't update the column to the current date. Any ideas why?
但它不会将列更新为当前日期。任何想法为什么?
回答by Michael Berkowski
Remove the quotes from NOW(). As a function call, it should be unquoted.
从 中删除引号NOW()。作为函数调用,它应该不加引号。
UPDATE users SET last_logged = NOW() WHERE id = 1
回答by whytheq
MS SQL uses GETDATE()rather than NOW()
MS SQL 使用GETDATE()而不是NOW()
(Just an FYI)
In SQL-ServerI now use SYSDATETIME():
(仅供参考)
在SQL-Server我现在使用SYSDATETIME():
DECLARE @now DATETIME = DATEADD(dd,DATEDIFF(dd,'19000101',SYSDATETIME()),'19000101');

