根据MySQL PHP中的日期时间更新记录。

huangapple go评论70阅读模式
英文:

update recrod according to datetime in mysql php

问题

我有一个表名为 "info",其中包含一个名为 "lastupdated" 的列(数据类型为 datetime),我只想更新所有记录,其中 "updatedOn" 不等于当前日期/今天的日期。

以下是我的表 "info":

id  status  lastupdated
1   1       2010-01-01 13:25:02
2   NULL    2010-01-03 14:05:02
3   1       2010-01-02 13:30:01

我尝试了以下查询,但不起作用,我错在哪里?

UPDATE info SET status = NULL
WHERE lastupdated != '2020-01-03'
英文:

I have table name "info" with column "lastupdated" (datatype is datetime),I just want to update all
record where "updatedOn" is not equal to currentdate/today's date

Here is my table "info"

id		status		lastupdated
1		1			2010-01-01 13:25:02	
2		NULL		2010-01-03 14:05:02
3		1			2010-01-02 13:30:01

I tried with following query but not working,Where i am wrong ?

UPDATE info SET status = NULL
WHERE lastupdated != '2020-01-03'

答案1

得分: 0

你可以使用 MySQL 的 DATE() 函数进行比较:

UPDATE info SET status = NULL
WHERE DATE(lastupdated) != '2020-01-03';
英文:

You can use DATE() function of mysql to compare

UPDATE info SET status = NULL
WHERE DATE(lastupdated ) != '2020-01-03'

答案2

得分: 0

UPDATE info SET status = NULL WHERE DATE(lastupdated) != '2020-01-03'

英文:

> Try with Date() function

UPDATE info SET status = NULL WHERE DATE(lastupdated) != '2020-01-03'

huangapple
  • 本文由 发表于 2020年1月3日 18:21:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定