mysql日期时间函数总结

发布时间:2016-11-17 14:18:28 作者:JIALY 90次浏览

    1.now()

    返回服务器当前时间

    mysql> select now();
    +---------------------+
    | now()               |
    +---------------------+
    | 2016-11-17 14:32:15 |
    +---------------------+
    1 row in set (0.00 sec)

    2.dayofweek(date)

    返回日期date是星期几(1=星期天,2=星期一,……7=星期六,ODBC标准)

    mysql> select dayofweek(now()),now();
    +------------------+---------------------+
    | dayofweek(now()) | now()               |
    +------------------+---------------------+
    |                5 | 2016-11-17 14:26:00 |
    +------------------+---------------------+
    1 row in set (0.00 sec)

    3.weekday(date)

    返回日期date是星期几(0=星期一,1=星期二,……6= 星期天)

    mysql> select weekday(now()),now();
    +----------------+---------------------+
    | weekday(now()) | now()               |
    +----------------+---------------------+
    |              3 | 2016-11-17 14:30:58 |
    +----------------+---------------------+
    1 row in set (0.00 sec)

    4.dayofmonth(date)

    返回date是一月中的第几日(在1到31范围内)

    mysql> select dayofmonth(now()),now();
    +-------------------+---------------------+
    | dayofmonth(now()) | now()               |
    +-------------------+---------------------+
    |                19 | 2016-11-19 10:13:49 |
    +-------------------+---------------------+
    1 row in set (0.00 sec)

    5.dayofyear(date)

    返回date是一年中的第几日(在1到366范围内)

    mysql> select dayofyear(now()),now();
    +------------------+---------------------+
    | dayofyear(now()) | now()               |
    +------------------+---------------------+
    |              324 | 2016-11-19 10:15:23 |
    +------------------+---------------------+
    1 row in set (0.00 sec)

    6.month(date)

    返回date中的月份数值

    mysql> select month(now()),now();
    +--------------+---------------------+
    | month(now()) | now()               |
    +--------------+---------------------+
    |           11 | 2016-11-19 10:16:52 |
    +--------------+---------------------+
    1 row in set (0.00 sec)




关键字词: MYSQL 日期时间