MySQL如何实现日期加减函数
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,小编这次要给大家分享的是MySQL如何实现日期加减函数,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。1. addtime()为日期加上指定秒数select ad
千家信息网最后更新 2025年11月07日MySQL如何实现日期加减函数
小编这次要给大家分享的是MySQL如何实现日期加减函数,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。
1. addtime()
为日期加上指定秒数
select addtime(now(),1); -- 加1秒
2. adddate()
有两种用法,第二个参数直接填数字的话是为日期加上指定天数,填interval的话是为日期加上指定的interval时间
select adddate(now(),1); -- 加1天select adddate(now(), interval 1 day); -- 加1天select adddate(now(), interval 1 hour); --加1小时select adddate(now(), interval 1 minute); -- 加1分钟select adddate(now(), interval 1 second); -- 加1秒select adddate(now(), interval 1 microsecond); -- 加1毫秒select adddate(now(), interval 1 week); -- 加1周select adddate(now(), interval 1 month); -- 加1月select adddate(now(), interval 1 quarter); -- 加1季select adddate(now(), interval 1 year); -- 加1年
3. date_add()
为日期增加一个时间间隔,这个只能使用interval时间作为参数,用法和adddate()一致
select date_add(now(), interval 1 day); -- 加1天select date_add(now(), interval 1 hour); -- 加1小时select date_add(now(), interval 1 minute); -- 加1分钟select date_add(now(), interval 1 second); -- 加1秒select date_add(now(), interval 1 microsecond); -- 加1毫秒select date_add(now(), interval 1 week); -- 加1周select date_add(now(), interval 1 month); -- 加1月select date_add(now(), interval 1 quarter); -- 加1季select date_add(now(), interval 1 year); -- 加1年
4. subtime()
为日期减去指定秒数
select subtime(now(), 1); -- 减1秒
5. subdate()
与adddate()函数用法一致,有两种用法,第二个参数直接填数字的话是为日期减去指定天数,填interval的话是为日期减去指定的interval时间
select subdate(now(),1); -- 减1天select subdate(now(), interval 1 day); -- 减1天select subdate(now(), interval 1 hour); --减1小时select subdate(now(), interval 1 minute); -- 减1分钟select subdate(now(), interval 1 second); -- 减1秒select subdate(now(), interval 1 microsecond); -- 减1毫秒select subdate(now(), interval 1 week); -- 减1周select subdate(now(), interval 1 month); -- 减1月select subdate(now(), interval 1 quarter); -- 减1季select subdate(now(), interval 1 year); -- 减1年
6. date_sub()
与date_add()函数用法一致,为日期减去一个时间间隔,这个只能使用interval时间作为参数
select date_sub(now(), interval 1 day); -- 减1天select date_sub(now(), interval 1 hour); --减1小时select date_sub(now(), interval 1 minute); -- 减1分钟select date_sub(now(), interval 1 second); -- 减1秒select date_sub(now(), interval 1 microsecond); -- 减1毫秒select date_sub(now(), interval 1 week); -- 减1周select date_sub(now(), interval 1 month); -- 减1月select date_sub(now(), interval 1 quarter); -- 减1季select date_sub(now(), interval 1 year); -- 减1年
看完这篇关于MySQL如何实现日期加减函数的文章,如果觉得文章内容写得不错的话,可以把它分享出去给更多人看到。
日期
时间
函数
参数
小时
一致
文章
内容
天数
数字
不错
兴趣
内容丰富
小伙
小伙伴
更多
篇文章
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全主题卡通画
2021网络安全知识比拼
我图网网络安全
如何挑选云服务器带宽
关于网络安全建言献策
ftp服务器21端口安全吗
wps按图表关联数据库
河北网欣网络技术
数据库建立小数点类型
中专学网络技术怎么样
pi实时数据库怎么导出数据
网络安全需要数学和英语好吗
东台软件开发
附加数据库无法打开日志文件
什么作业学数据库
计算机应用的主流网络技术
计算机网络技术和网络安全区别
关系数据库与sql语言
网络安全知识口诀童谣
工控网络安全学术会议
建设银行的网络安全员
甘肃网络技术服务价格表格
在服务器上建立ftp
快门科技网络技术有限公司
福建网络安全安全平台作业
升级服务器系统
电脑显示服务器打不开怎么办
请输入网络安全密匙路由器
智能手机铃声软件开发
涉密网络安全与