如何在 MySQL 中减去天数
如何减去 MySQL 中的时间?例如,今天是 3 月 16 日;我想减去 15 天来达到 3 月 1 日。有什么方法可以从当前日期减去 15 天吗?
How can I subtract time in MySQL? For example, today is 16 March; I want to subtract 15 days to reach 1 March. Are there any methods that can be used to subtract 15 days from the current date?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有关单位列表,请参阅 http ://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add
For a list of units see http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add
与这个问题不完全相关,但与标题相关:
文档:MySQL
SUBTIME
函数Not entirely related to this question but is related to the title:
Documentation: MySQL
SUBTIME
function用途:
保持日期时间精度。
Use:
to keep the datetime precision.
可以使用:
SELECT DATE(NOW()-INTERVAL 15 DAY);
当您想要减去天数时,
。为了减去时间(例如 15 分钟),应执行以下操作:
SELECT(DATE_SUB(NOW(), INTERVAL '15:0' MINUTE_SECOND));
再次添加参考链接:- < a href="https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-add" rel="nofollow noreferrer">https://dev.mysql .com/doc/refman/8.0/en/date-and-time-functions.html#function_date-add。
You can use this :
SELECT DATE(NOW()-INTERVAL 15 DAY);
for when you want to subtract the number of days.
In order to subtract the time instead, say 15 minutes, the following should work:
SELECT(DATE_SUB(NOW(), INTERVAL '15:0' MINUTE_SECOND));
Adding the reference link again :- https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-add.
是的,可以在 Mysql
lastname 中使用date function,changedat是字段名称,employee_audit是表名称。
我的日期已减去 15 天 - 请检查图片。谢谢
Yes its possible using date function in Mysql
lastname and changedat is field name and employee_audit is table name.
I have subtract 15 days from my date - check image please. thanks