当前位置: 首页 > news >正文

【超详细】HIVE 日期函数(当前日期、时间戳转换、前一天日期等)

文章目录

    • 相关文献
    • 常量:当前日期、时间戳
    • 前一天日期、后一天日期
    • 获取日期中的年、季度、月、周、日、小时、分、秒等
    • 时间戳转换
      • 时间戳 to 日期
      • 日期 to 时间戳
    • 日期之间月、天数差

作者:小猪快跑

基础数学&计算数学,从事优化领域5年+,主要研究方向:MIP求解器、整数规划、随机规划、智能优化算法。

如有错误,欢迎指正。如有更好的算法,也欢迎交流!!!——@小猪快跑

相关文献

  • LanguageManual UDF - Apache Hive - Apache Software Foundation

常量:当前日期、时间戳

返回类型名称样例描述
datecurrent_datecurrent_date = 2024-01-01返回查询评估开始时的当前日期(从 Hive 1.2.0 开始)。同一查询中的所有current_date调用都返回相同的值。
timestampcurrent_timestampcurrent_timestamp = 2024-01-01 00:00:00返回查询评估开始时的当前时间戳(从 Hive 1.2.0 开始)。同一查询中的所有current_date调用都返回相同的值。

前一天日期、后一天日期

返回类型名称样例
pre 2.1.0: string 2.1.0 on: datedate_add(date/timestamp/string startdate, tinyint/smallint/int days)date_add(‘2008-12-31’, 1) = 2009-01-01
pre 2.1.0: string 2.1.0 on: datedate_sub(date/timestamp/string startdate, tinyint/smallint/int days)date_sub(‘2008-12-31’, 1) = 2008-12-30
date_sub(current_date, 1) -- 昨天
date_add(current_date, 1) -- 明天

获取日期中的年、季度、月、周、日、小时、分、秒等

返回类型名称样例描述
intyear(string date)year("1970-01-01") = 1970
year("1970-01-01 00:00:00") = 1970
intquarter(date/timestamp/string)quarter('2015-04-08') = 2季度
intmonth(string date)month("1970-11-01 00:00:00") = 11
month("1970-11-01") = 11
intweekofyear(string date)weekofyear("1970-11-01 00:00:00") = 44
weekofyear("1970-11-01") = 44
intday(string date) dayofmonth(date)day("1970-11-01 00:00:00") = 1
day("1970-11-01") = 1
inthour(string date)hour('2009-07-30 12:58:59') = 12小时
hour('12:58:59') = 12
intminute(string date)
intsecond(string date)
stringlast_day(string date)last_day('2015-01-14') = 2015-01-31当月最后一天
stringnext_day(string start_date, string day_of_week)next_day('2015-01-14', 'TU') = 2015-01-20给定日期后最近的星期几

时间戳转换

时间戳 to 日期

返回类型名称样例描述
stringfrom_unixtime(bigint unixtime[, string pattern])from_unixtime(0)=1970-01-01 00:00:00(1970-01-01 00:00:00 UTC)之后多少秒的时间,注意不同时区结果不同

日期 to 时间戳

返回类型名称样例描述
bigintunix_timestamp(string date)unix_timestamp(‘2009-03-20 11:30:01’) = 1237573801(1970-01-01 00:00:00 UTC)之后多少秒,注意不同时区结果不同
bigintunix_timestamp(string date, string pattern)unix_timestamp(‘2009-03-20’, ‘yyyy-MM-dd’) = 1237532400(1970-01-01 00:00:00 UTC)之后多少秒,注意不同时区结果不同 https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html

日期之间月、天数差

返回类型名称样例描述
doublemonths_between(date1, date2)months_between(‘1997-02-28 10:30:00’, ‘1996-10-30’) = 3.94959677返回日期 date1 和 date2 之间的月数(从 Hive 1.2.0 开始)。如果 date1 晚于 date2,则结果为正数。如果 date1 早于 date2,则结果为负数。 date1 和 date2 类型:timestamp | ‘yyyy-MM-dd’ | ‘yyyy-MM-dd HH:mm:ss’
intdatediff(string enddate, string startdate)datediff(‘2009-03-01’, ‘2009-02-27’) = 2
http://www.lryc.cn/news/306108.html

相关文章:

  • [ffmpeg] x264 配置参数解析
  • GO语言基础总结
  • 飞天使-linux操作的一些技巧与知识点7-devops
  • Sora:视频生成模型作为世界模拟器
  • FairyGUI × Cocos Creator 3.x 使用方式
  • 基于Java的养生健康管理系统
  • Python课堂16——异常查找及处理
  • 任务书参考答案-模块1任务一
  • 2023最新盲盒交友脱单系统源码
  • Half-Band filter(半带滤波器)
  • 2024年环境安全科学、材料工程与制造国际学术会议(ESSMEM2024)
  • 常用路径规划算法简介及python程序
  • 计算x的对数math.log(x)math.log(x, a)math.log2(x)math.log10(x)
  • Golin 弱口令/漏洞/扫描/等保/基线核查的快速安全检查小工具
  • 【JavaEE】_HttpServlet类
  • 11-pytorch-使用自己的数据集测试
  • 数据安全之路:深入了解MySQL的行锁与表锁机制
  • 【深度学习】Pytorch 教程(十二):PyTorch数据结构:4、张量操作(3):张量修改操作(拆分、拓展、修改)
  • 适合新手博主站长使用的免费响应式WordPress博客主题JianYue
  • FPGA OSERDESE2
  • 如何卸载Erlang以及RabbitMQ
  • ros自定义action记录
  • 挑战30天学完Python:Day18 正则表达式
  • 力扣● 343. 整数拆分 ● 96.不同的二叉搜索树
  • 游戏同步+游戏中的网络模块
  • 【03】逆序数组
  • 基于Prony算法的系统参数辨识matlab仿真
  • 创建第一个React项目
  • Redis篇之Redis持久化的实现
  • dpdk环境搭建和工作原理