zoukankan      html  css  js  c++  java
  • Hive日期函数总结(转学习使用)

    一、时间戳函数

    1、获取当前时区的UNIX时间戳:select unix_timestamp();

    2、将指定时间转为UNIX时间戳: select unix_timestamp('2012-03-03 11:45:31');

    3、将指定的实际转为贵UNIX时间戳:select unix_timestamp('2018-08-08 16:22:01','yyyy-MM-dd HH:mm:ss');

    二、时间戳转日期

    1、select from_unixtime(1533716521);2018-08-08 16:22:01 

    2、select from_unixtime(1533716521,'yyyyMMdd'); 20180808
    3、select from_unixtime(1533716521,'yyyy-MM-dd HH:mm:ss'); 2018-08-08 16:22:01 

    三、获取系统当前时间

     select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss');

    四、日期转换为其他格式的日期

    select from_unixtime(unix_timestamp('2018-08-08 16:28:21','yyyy-MM-dd HH:mm:ss'),'yyyyMMdd');20180808

    3.获取当前日期: current_date
    select current_date ;2018-08-08

    4.日期时间转日期:to_date(string timestamp)
    select to_date('2018-08-08 17:12:00') ;2018-08-08

    分区参数转日期:

    to_date(from_unixtime(unix_timestamp('${dt}','yyyyMMdd')))

    分区参数当月第一天日期:
    to_date(from_unixtime(unix_timestamp(concat(substr('${dt}',1,6),'01'),'yyyyMMdd')))

    5.计算两个日期之间的天数: datediff
    select datediff('2018-08-08','2018-08-01') ; 7

    6.日期增加和减少: date_add/date_sub(string startdate,int days)
    select date_add('2018-08-04',1) , date_sub('2018-08-04',1) ; 2018-08-05 2018-08-03

    7.其他日期函数
    查询当前系统时间(包括毫秒数):` current_timestamp;

    查询当月第几天: dayofmonth(current_date);

    月末: last_day(current_date)

    当月第1天: date_sub(current_date,dayofmonth(current_date)-1)

    年:year(date)

    月:month(date)

    日:day(date)

    小时:hour(date)

    分:minute(date)

    秒:second(date)

    第几周:weekofyear(date)

    下个月第1天: `add_months(date_sub(current_date,dayofmonth(current_date)-1),1)

  • 相关阅读:
    vscode圣诞帽
    阿里java代码检测工具p3c
    elasticsearch 二、elasticsearch-head安装
    elasticsearch 一、环境配置
    针对json的查询--alibaba的开源项目jsonq
    macos下golang 1.9配置
    此请求已被阻止,因为当用在 GET 请求中时,会将敏感信息透漏给第三方网站。若要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet。
    mvc webapi路由重写
    《Java编程的逻辑》终于上市了!
    《Java编程的逻辑》
  • 原文地址:https://www.cnblogs.com/yfb918/p/10813437.html
Copyright © 2011-2022 走看看