sql语句函数笔记

  1. 返回从0000年到现在的天数
    to_days("2015-01-04")
  2. 将时间/日期间隔添加到日期
    adddate("2015-01-03",INTERVAL 1 day) #2015-01-04
  3. TIMESTAMPDIFF
    #计算相差天数: select TIMESTAMPDIFF(DAY,'2019-05-20', '2019-05-21'); # 1
    #计算相差小时数: select TIMESTAMPDIFF(HOUR, '2015-03-22 07:00:00', '2015-03-22 18:00:00'); # 11
    #计算相差秒数: select TIMESTAMPDIFF(SECOND, '2015-03-22 07:00:00', '2015-03-22 7:01:01'); # 61
  4. 返回值是相差的天数
    DATEDIFF('2007-12-31','2007-12-30'); # 1 DATEDIFF('2010-12-30','2010-12-31'); # -1
  5. 从日期减去指定的时间间隔
    DATE_SUB("2008-12-29",INTERVAL 2 DAY) #2008-12-27
  6. interval
    "2015-01-03"+interval'1' day #2015-01-04

你可能感兴趣的:(数据库mysql/redis,sql,笔记,数据库)