英文:
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'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论