MySQL 向 now() 函数添加 6 小时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3268167/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:34:21  来源:igfitidea点击:

Add 6 hours to now() function

mysql

提问by sark9012

I dont know if this is possible. I have researched it and cant find anything. I want to add 6 hours onto the value now() will return. At the moment it comes back in a datetime format in the database.

我不知道这是否可能。我已经研究过了,找不到任何东西。我想在 now() 返回的值上增加 6 小时。目前它以数据库中的日期时间格式返回。

Is there another function where i can add 6 hours onto the current time? Thankyou

是否有另一个功能可以让我在当前时间上增加 6 小时?谢谢

回答by Mark Byers

Use NOW() + INTERVAL 6 HOUR. As an example:

使用NOW() + INTERVAL 6 HOUR. 举个例子:

SELECT NOW(), NOW() + INTERVAL 6 HOUR

Result:

结果:

'2010-07-16 21:25:17', '2010-07-17 03:25:17'

回答by Justin Ethier

You could use DATE_ADD:

您可以使用DATE_ADD

SELECT DATE_ADD(now(), INTERVAL 6 HOUR);

回答by Phil

DATE_ADD(NOW(), INTERVAL 6 HOUR)

DATE_ADD(NOW(), INTERVAL 6 HOUR)

回答by OMG Ponies

Use the DATE_ADD function:

使用DATE_ADD 函数

SELECT DATE_ADD(NOW(), INTERVAL 6 HOUR)

回答by Will A

I thinkyou want DateAdd - see here.

你想要 DateAdd - 请看这里

回答by barwin

I'm always forgetting the correct syntax for this, so I find this page of the mysql doc to be a good bookmark:

我总是忘记正确的语法,所以我发现 mysql 文档的这个页面是一个很好的书签:

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

It's complete with examples like those that others posted

它包含其他人发布的示例