HIVE SQL时间函数

目录

current_timestamp()获取当前时间

sql 复制代码
select current_timestamp();

输出:2023-11-23 11:31:31.531

unix_timestamp()获取当前时区的UNIX时间戳

sql 复制代码
select unix_timestamp();

输出:1700710598

from_unixtime()时间戳转日期函数

sql 复制代码
select from_unixtime(1700710598);

输出:2023-11-23 11:36:38

unix_timestamp(string date)日期转时间戳函数

sql 复制代码
select unix_timestamp('2023-11-23 11:36:38');

输出:1700710598

提取日期中的年月日时分秒

sql 复制代码
> select year(current_timestamp());

输出:2023

sql 复制代码
select month(current_timestamp());

输出:11

sql 复制代码
select day(current_timestamp());

输出:23

sql 复制代码
select hour(current_timestamp());

输出:13

sql 复制代码
select minute(current_timestamp());

输出:39

sql 复制代码
select second(current_timestamp());

输出:25

weekofyear (string date)日期转周函数

sql 复制代码
select weekofyear(current_timestamp());

输出:47

日期比较函数datediff(string enddate, string startdate)

sql 复制代码
select datediff(current_timestamp(),'2023-11-20');

输出:3

日期增加/减少函数

date_add(string startdate, int days)

date_sub (string startdate, int days)

sql 复制代码
select date_add(current_timestamp(),3);

输出:2023-11-26

sql 复制代码
select date_sub(current_timestamp(),3);

输出:2023-11-20

相关推荐
Je1lyfish34 分钟前
CMU15-445 (2026 Spring) Project#2 - B+ Tree
linux·数据结构·数据库·c++·sql·spring·oracle
Schengshuo43 分钟前
【Oracle11g SQL详解】UPDATE 和 DELETE 操作的正确使用
数据库·sql
Y001112362 小时前
Day6-MySQL-函数
数据库·sql·mysql
V1ncent Chen2 小时前
SQL大师之路 09 模式匹配(正则表达式)
数据库·sql·mysql·正则表达式·数据分析
盛源_013 小时前
hive表视图
数据仓库·hive·hadoop
杨云龙UP3 小时前
Oracle 19c RAC多节点运行状态最简排查指南_20260316
linux·运维·服务器·数据库·sql·oracle
pupudawang3 小时前
SQL-触发器(trigger)的详解以及代码演示
服务器·数据库·sql
不过普通话一乙不改名4 小时前
十二:InnoDB MVCC(多版本并发控制)
sql
数据库小组5 小时前
NineData 社区版慢 SQL 功能能做什么?给 DBA 的一套本地化治理工具
数据库·sql·dba·慢sql·数据库管理工具·ninedata·迁移工具
马里马里奥-6 小时前
文献阅读:LinkAlign:面向真实世界大规模多数据库文本转SQL任务的可扩展模式链接方法
数据库·sql