zoukankan      html  css  js  c++  java
  • Hive时间处理

    Hive时间处理

    时间戳:unix_timestamp

    时间戳转日期:from_unixtime

    常用时间写法

    时间 Hive语句
    上月1号 trunc(add_months(current_date(),-1),'MM')
    本月1号 trunc(current_date(),'MM')
    下月1号 trunc(add_months(current_date(),1),'MM')
    本月时间范围 substr(date,0,10)>=trunc(current_date(),'MM') and substr(date,0,10)<trunc(add_months(current_date(),1),'MM')
    时间偏移一个月 add_months(current_date,-1)
    上月时间范围 substr(date,0,10)>=trunc(add_months(current_date(),-1),'MM') and substr(date,0,10)<trunc(add_months(current_date(),0),'MM')
    近一周数据 substr(date,0,10)>=date_sub(current_date(),7) and substr(date,0,10)<current_date()
    近一月数据 substr(date,0,10)>=date_sub(current_date(),30) and substr(date,0,10)<current_date()
    本周周一日期 date_sub(current_date(),cast(date_format(current_date(),'u') as int)-1)
    上周周一日期 date_sub(current_date(),cast(date_format(current_date(),'u') as int)-1+7)
    上周时间 substr(date,0,10)>=date_sub(current_date(),cast(date_format(current_date(),'u') as int)-1+7) and substr(date,0,10)<date_sub(current_date(),cast(date_format(current_date(),'u') as int)-1)
    本周时间 substr(date,0,10)>=date_sub(current_date(),cast(date_format(current_date(),'u') as int)-1) and substr(date,0,10)<current_date()
    今年年初日期 trunc(current_date(),'YYYY')
    今年(到昨日) substr(date,0,10)>=trunc(current_date(),'YYYY') and substr(date,0,10)<current_date()
    今年(到上月) substr(date,0,10)>=trunc(current_date(),'YYYY') and substr(date,0,10)<trunc(current_date(),'MM')
  • 相关阅读:
    selenium执行js代码的两个方法
    PostgresSQL数据库安装及操作
    [Python]requests使用代理
    linux下postgreSQL初始化设置方法
    如何用Jenkins自动化部署项目(教程,从零到搭建完成)
    Python笔记:Geopython GIS相关库
    Postman接口&压力测试
    python+django+vue实现前后端分离项目和部署的操作
    python-Django-1.8.2中文文档
    CSS详细解读定位
  • 原文地址:https://www.cnblogs.com/junstudys/p/12198016.html
Copyright © 2011-2022 走看看