zoukankan      html  css  js  c++  java
  • 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年
  • 相关阅读:
    关于多态的一些问题
    003 关于shell基础,大数据的前期准备
    002 在大数据中基础的llinux基本命令
    013 MapReduce八股文的wordcount应用
    接口里语句的修饰问题
    Apache Rewrite url重定向功能的简单配置
    学习笔记 --- 缓存、动态页面静态化、网站优化
    使用PHP连接、操纵Memcached的原理和教程
    Apache中关于页面缓存的设置
    缓存(之一) 使用Apache Httpd实现http缓存
  • 原文地址:https://www.cnblogs.com/luo-jian/p/12882374.html
Copyright © 2011-2022 走看看