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年
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载荒野乱斗测试服 安卓版v61.10.3
下载荒野乱斗彩虹服 安卓版v61.10.3
下载寒霜启示录 安卓版v1.25.10
寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
末日城堡免广告版 安卓最新版v0.7.1
末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
甜蜜人生模拟器 最新版v1.4.5
甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
武器锻造师内置功能菜单 v10.4
武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
开放空间overfield 安卓版v1.0.5
开放空间Overfield是一款箱庭养成经营手游,让你在广阔