zoukankan      html  css  js  c++  java
  • Mysql日期时间Extract函数介绍

    MySQL日期时间Extract函数的优点在于可以选取日期时间的各个部分,从年一直到微秒,让我们对MySQL日期时间的处理更为轻松。

    MySQL 日期时间 Extract(选取)函数。
    1. 选取日期时间的各个部分:日期、时间、年、季度、月、日、小时、分钟、秒、微秒

    [sql] view plain copy
     
    1. set @dt = '2008-09-10 07:15:30.123456';    
    2. select date(@dt); -- 2008-09-10    
    3. select time(@dt); -- 07:15:30.123456    
    4. select year(@dt); -- 2008    
    5. select quarter(@dt); -- 3    
    6. select month(@dt); -- 9    
    7. select week(@dt); -- 36    
    8. select day(@dt); -- 10    
    9. select hour(@dt); -- 7    
    10. select minute(@dt); -- 15    
    11. select second(@dt); -- 30    
    12. select microsecond(@dt); -- 123456  

    2. MySQL Extract() 函数,可以上面实现类似的功能

    [sql] view plain copy
     
    1. set @dt = '2008-09-10 07:15:30.123456';    
    2. select extract(year from @dt); -- 2008    
    3. select extract(quarter from @dt); -- 3    
    4. select extract(month from @dt); -- 9    
    5. select extract(week from @dt); -- 36    
    6. select extract(day from @dt); -- 10    
    7. select extract(hour from @dt); -- 7    
    8. select extract(minute from @dt); -- 15    
    9. select extract(second from @dt); -- 30    
    10. select extract(microsecond from @dt); -- 123456    
    11.    
    12. select extract(year_month from @dt); -- 200809    
    13. select extract(day_hour from @dt); -- 1007    
    14. select extract(day_minute from @dt); -- 100715    
    15. select extract(day_second from @dt); -- 10071530    
    16. select extract(day_microsecond from @dt); -- 10071530123456    
    17. select extract(hour_minute from @dt); -- 715    
    18. select extract(hour_second from @dt); -- 71530    
    19. select extract(hour_microsecond from @dt); -- 71530123456    
    20. select extract(minute_second from @dt); -- 1530    
    21. select extract(minute_microsecond from @dt); -- 1530123456    
    22. select extract(second_microsecond from @dt); -- 30123456  

    MySQL Extract() 函数除了没有date(),time() 的功能外,其他功能一应具全。并且还具有选取‘day_microsecond’ 等功能。注意这里不是只选取 day 和 microsecond,而是从日期的 day 部分一直选取到 microsecond 部分。

  • 相关阅读:
    获得 Web Service 方法的描述信息
    make menuconfig 报错
    汇编调用c函数为什么要设置栈
    UBoot Makefile文件分析
    UBoot启动过程完全分析(转)
    (转)在fedora12下用crosstoolng建立armlinux交叉编译环境
    UBoot编译过程完全分析(转)
    雷军:给互联网创业者的“七字”建议
    uboot根目录下makefile
    Redhat 5 配置Samba服务器
  • 原文地址:https://www.cnblogs.com/maohuidong/p/7976241.html
Copyright © 2011-2022 走看看