运维联盟俱乐部

 找回密码
 立即注册
查看: 2098|回复: 0

MySQL 获得当前日期时间 函数

[复制链接]
  • TA的每日心情
    开心
    2023-8-9 11:05
  • 发表于 2021-12-16 14:04:15 | 显示全部楼层 |阅读模式
    获得当前日期+时间(date + time)函数:now()
    1. mysql> select now();
    2. +---------------------+
    3. | now()               |
    4. +---------------------+
    5. | 2021-12-16 13:59:56 |
    6. +---------------------+
    7. 1 row in set (0.00 sec)
    复制代码
    获得当前日期+时间(date + time)函数:sysdate()
    sysdate() 日期时间函数跟 now() 类似,不同之处在于:now() 在执行开始时值就得到了, sysdate() 在函数执行时动态得到值。
    1. mysql> select sysdate();
    2. +---------------------+
    3. | sysdate()           |
    4. +---------------------+
    5. | 2021-12-16 14:00:03 |
    6. +---------------------+
    7. 1 row in set (0.00 sec)
    复制代码
    1. mysql> select now(),sleep(3),sysdate();
    2. +---------------------+----------+---------------------+
    3. | now()               | sleep(3) | sysdate()           |
    4. +---------------------+----------+---------------------+
    5. | 2021-12-16 14:00:30 |        0 | 2021-12-16 14:00:33 |
    6. +---------------------+----------+---------------------+
    7. 1 row in set (3.00 sec)
    复制代码
    MySQL 获得当前时间戳函数:current_timestamp, current_timestamp()
    1. mysql> select current_timestamp, current_timestamp();
    2. +---------------------+---------------------+
    3. | current_timestamp   | current_timestamp() |
    4. +---------------------+---------------------+
    5. | 2021-12-16 14:02:32 | 2021-12-16 14:02:32 |
    6. +---------------------+---------------------+
    7. 1 row in set (0.00 sec)
    复制代码




    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    运维联盟俱乐部 ( 冀ICP备19036648号 )

    GMT+8, 2024-4-29 07:30 , Processed in 0.058327 second(s), 31 queries , Gzip On.

    Powered by Discuz! X3.4

    © 2001-2023 Discuz! Team.

    快速回复 返回顶部 返回列表