zoukankan      html  css  js  c++  java
  • mysql日期时间函数(常用的)

    mysql> SELECT NOW();  #返回(打印)当前日期和时间
    +---------------------+
    | NOW() |
    +---------------------+
    | 2017-03-28 17:53:34 |
    +---------------------+
    1 row in set (0.01 sec)

    mysql> SELECT CURDATE();   #返回(打印)当前日期
    +------------+
    | CURDATE() |
    +------------+
    | 2017-03-28 |
    +------------+

    mysql> SELECT CURTIME();   #返回(打印)当前时间
    +-----------+
    | CURTIME() |
    +-----------+
    | 17:55:57 |
    +-----------+
    1 row in set (0.00 sec)

    mysql> SELECT DATE_ADD('2014-3-12', INTERVAL 365 DAY);  #日期变化
    +-----------------------------------------+
    | DATE_ADD('2014-3-12', INTERVAL 365 DAY) |
    +-----------------------------------------+
    | 2015-03-12 |
    +-----------------------------------------+
    1 row in set (0.00 sec)

    mysql> SELECT DATE_ADD('2014-3-12', INTERVAL -365 DAY);
    +------------------------------------------+
    | DATE_ADD('2014-3-12', INTERVAL -365 DAY) |
    +------------------------------------------+
    | 2013-03-12 |
    +------------------------------------------+
    1 row in set (0.00 sec)

    mysql> SELECT DATE_ADD('2014-3-12', INTERVAL 1 YEAR);
    +----------------------------------------+
    | DATE_ADD('2014-3-12', INTERVAL 1 YEAR) |
    +----------------------------------------+
    | 2015-03-12 |
    +----------------------------------------+
    1 row in set (0.00 sec)

    mysql> SELECT DATE_ADD('2014-3-12', INTERVAL 3 WEEK);
    +----------------------------------------+
    | DATE_ADD('2014-3-12', INTERVAL 3 WEEK) |
    +----------------------------------------+
    | 2014-04-02 |
    +----------------------------------------+
    1 row in set (0.00 sec)

    mysql> SELECT DATEDIFF('2013-3-12','2014-3-12');  #日期差值
    +-----------------------------------+
    | DATEDIFF('2013-3-12','2014-3-12') |
    +-----------------------------------+
    | -365 |
    +-----------------------------------+
    1 row in set (0.01 sec)

    mysql> SELECT DATE_FORMAT('2014-3-2', '%m/%d/%Y');  #日期格式化
    +-------------------------------------+ 
    | DATE_FORMAT('2014-3-2', '%m/%d/%Y') |
    +-------------------------------------+
    | 03/02/2014 |
    +-------------------------------------+
    1 row in set (0.00 sec)

  • 相关阅读:
    可图性判定HavelHakimi定理
    并查集入门
    js数组和函数应用
    DOM用法及应用
    javascript基础知识
    表单
    PHP变量
    30天自制操作系统开发笔记——IDT中断描述符表
    《30天自制操作系统》学习笔记——汇编程序磁盘BIOS调用
    汇编指令: LGDT、LIDT、LLDT、LMSW、LOADALL、LOADALL286、LOCK、LODSB、LODSW、LODSD
  • 原文地址:https://www.cnblogs.com/toudoubao/p/6636150.html
Copyright © 2011-2022 走看看