MySQL 的 now() +1 天
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3887509/
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
MySQL's now() +1 day
提问by Qiao
I'm using now()
in MySQL query.
我now()
在 MySQL 查询中使用。
INSERT INTO table SET data = '$data', date = now()
But I want to add 1 day to this date (so that date
should contain tomorrow).
Is it possible?
但我想在这个日期上加 1 天(这样date
应该包含明天)。
是否可以?
回答by Mark Byers
You can use:
您可以使用:
NOW() + INTERVAL 1 DAY
If you are only interested in the date, not the date and time then you can use CURDATE instead of NOW:
如果您只对日期感兴趣,而不对日期和时间感兴趣,那么您可以使用 CURDATE 而不是 NOW:
CURDATE() + INTERVAL 1 DAY
回答by Igor Qwerty
better use quoted `data`
and `date`
. AFAIR these may be reserved words
my version is:
更好地使用引用`data`
和`date`
。AFAIR 这些可能是保留字,我的版本是:
INSERT INTO `table` ( `data` , `date` ) VALUES('".$date."',NOW()+INTERVAL 1 DAY);
回答by Nicolas Bottarini
Try doing: INSERT INTO table(data, date) VALUES ('$data', now() + interval 1 day)
尝试做: INSERT INTO table(data, date) VALUES ('$data', now() + interval 1 day)
回答by user1239611
INSERT INTO `table` ( `data` , `date` ) VALUES('".$data."',NOW()+INTERVAL 1 DAY);