zoukankan      html  css  js  c++  java
  • 【mysql时间类sql处理总结】

    获取当前时间:【年-月-日 时:分:秒】

    -- 格式:2020-05-15 19:57:47
    select now() from test -- 建议
    select current_timestamp from test
    select current_timestamp() from test
    select localtime from test
    select localtime() from test

    获取当前时间:【年-月-日】

    -- 格式:2020-05-15
    select curdate() from test -- 建议
    select current_date from test
    select current_date() from test

    获取当前时间:【时:分:秒】

    -- 格式:19:06:49
    select curtime() from test
    select current_time from test
    select current_time() from test

    获取月份中的最后一天:【年-月-日】

    -- 格式:2020-02-29
    select last_day('2020-02-01');

    获取当前月份有多少天:【天数】

    -- 格式:31
    select day(last_day(now())) as days;

    获取两个时间之间得天数:【天数】

    -- 格式 4
    select datediff('2020-05-05', '2020-05-01') from test;

    获取时间得差值:【时:分:秒】

    -- 格式:08:08:08
    select timediff('2008-08-08 08:08:08', '2008-08-08 00:00:00') from test;

    时间-字符串-时间戳之间的转换

    时间转字符串:

    -- 格式:2020-05-15 19:23:25
    select date_format(now(), '%Y-%m-%d %H:%i:%s');

    时间转时间戳:

    -- 格式:1589531039
    select unix_timestamp(now());

    时间戳转字符串:

    -- 格式:2018-05-02 20:16:23
    select from_unixtime(1525263383, '%Y-%m-%d %H:%i:%s');

    时间戳转时间:

    -- 2018-05-02 20:16:23
    select from_unixtime(1525263383);

    字符串转时间:

    -- 格式:2020-05-02 19:20:20
    select str_to_date('2020-05-02 19:20:20','%Y-%m-%d %H:%i:%s');

    字符串转时间戳:

    -- 1525263850
    select unix_timestamp('2018-05-02 20:24:10');

    参考:

    1. https://www.cnblogs.com/blueness-sunshine/p/4912058.html

    2. https://www.cnblogs.com/zuiyue_jing/p/12769486.html

    注意:本篇文章仅用于个人学习,如有侵权,联系删除!!!

    持续更新!!!

  • 相关阅读:
    Matlab smooth函数原理
    Pandas中的高级索引loc、iloc、ix精简概括
    QT常见错误:"multiple definition of xxx"
    Github术语解释
    数据反转 LSB
    LSB最低有效位和MSB最高有效位
    Modbus通信CRC16校验程序
    CRC16常见几个标准的算法及C语言实现
    DB9 公头母头引脚定义及连接
    hdu 2577 How to Type(dp)
  • 原文地址:https://www.cnblogs.com/flyinghome/p/12895546.html
Copyright © 2011-2022 走看看