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 部分。

  • 相关阅读:
    java匿名内部类
    【绝对给力】Android开发免豆资料(教程+工具+源码)地址汇总
    【绝对给力】Android开发免豆资料(教程+工具+源码)地址汇总
    【分享】Java学习之路:不走弯路,就是捷径
    【分享】熟练的Java程序员应该掌握哪些技术?
    【分享】熟练的Java程序员应该掌握哪些技术?
    android 小知识点
    android 小知识点
    Eclipse快捷键大全
    Eclipse快捷键大全
  • 原文地址:https://www.cnblogs.com/maohuidong/p/7976241.html
Copyright © 2011-2022 走看看