zoukankan      html  css  js  c++  java
  • hive sql的常用日期处理函数总结

    1)date_format函数(根据格式整理日期)

      作用:把一个字符串日期格式化为指定的格式。

    select date_format('2017-01-01','yyyy-MM-dd HH:mm:ss');  --日期字符串必须满足yyyy-MM-dd格式    

      结果:2017-01-01 00:00:00

    2)date_add、date_sub函数(加减日期)

      作用:把一个字符串日期格式加一天、减一天。

    select date_add('2019-01-01',1);       --字符串必须满足yyyy-MM-dd格式    

      结果:2019-01-02

    select date_sub('2019-01-01',1);   --字符串必须满足yyyy-MM-dd格式 

      结果:2018-12-31

    3)next_day函数

      作用:得到一个字符串日期的下周几的具体日期

    select next_date('2020-01-01','Fri');     --得到2020-01-01往后的第一个周五

      结果:2020-01-03

    4)last_day函数(求当月最后一天日期)

      作用:求当月的最后一天日期

    select last_day('2020-01-01');

      结果:select last_day('2020-01-01');

    5)from_unixtime(‘bigint时间戳’,‘pattern’)函数  5,6在一起用,常用来把非yyyy-MM-dd的日期字符串转为标准的yyyy-MM-dd的日期字符串

      作用:把一个大数字时间戳,转换为指定格式的日期字符串

    select from_unixtime(1517725479,'yyyy-MM-dd HH:dd:ss');
    select from_unixtime(1517725479,'yyyyMMdd');

      结果:2018-02-04 14:04:39

         20180204

    6)unix_timestamp('日期字符串',‘pattern’)   5,6在一起用,常用来把非yyyy-MM-dd的日期字符串转为标准的yyyy-MM-dd的日期字符串

      作用:把指定格式的日期转成时间戳

    select unix_timestamp('2020/01/01','yyyy/MM/dd');

      结果:1577808000

    7)current_date()

      作用:得到当前的日期字符串

    select current_date();

      结果:2020-01-01

    8)current_timestamp()

      作用:得到当前的时间字符串

    select current_timestamp();

      结果:2020-01-01 13:52:46.018

    9) unix_timestamp()

      作用:得到当前的时间戳

    select unix_timestamp();

      结果:1577858367

  • 相关阅读:
    Blazor server VS Blazor WebAssembly
    DataTable 差集Except、交集Intersect、并集Union
    Power BI Anomaly Detection
    Power BI智能叙述
    Configure the Secure Store Service in SharePoint Server
    小批量excel数据导入oracle
    python批量写入oracle
    centos7安装java,配置的环境变量不生效 -bash: java: command not found
    nebula docker三件套组件版本问题
    shell删除指定行
  • 原文地址:https://www.cnblogs.com/w-j-q/p/14774876.html
Copyright © 2011-2022 走看看