• 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)

  • 相关阅读:
    leetcode ---Search a 2D Matrix
    leetcode ---Search for a Range
    LeetCode--Search in Rotated Sorted Array
    LeetCode--setatrixzeroes
    LeetCode--sortColor
    LeetCode--Spiral Matrix
    java io类 和servlet类 的UML图表示
    servlet web.xml配置详解
    解决json日期格式带T问题
    在拦截器中获取请求参数,[Ljava.lang.String; cannot be cast to java.lang.String报错
  • 原文地址:https://www.cnblogs.com/yfb918/p/10813437.html
Copyright © 2020-2023  润新知