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

相关推荐
摇滚侠2 小时前
MyBatis 入门到项目实战 特殊 SQL 的执行 34-37
java·sql·mybatis
layflat_coder3 小时前
NL2SQL 正确率怎么提升:ChatBI 的 `<error-msg>` 错误反馈闭环
sql
摇滚侠7 小时前
MyBatis 入门到项目实战 MyBatis 分页插件 65-66
java·开发语言·sql·mybatis
北风toto7 小时前
深度拆解:本体与智能体协同生成SQL的底层逻辑与工程实践
数据库·sql·microsoft
倒流时光三十年7 小时前
PostgreSQL NULLIF 条件表达式函数详解
数据库·sql·postgresql
czhc11400756638 小时前
614 :代码修正: halcon 注销;sql配置修改
sql
吴声子夜歌11 小时前
SQL经典实例——插入、更新和删除
数据库·sql
山峰哥11 小时前
VBA数据结构之争:Dictionary vs Collection,性能差3倍!
服务器·数据结构·数据库·windows·sql·算法·哈希算法
仙俊红1 天前
SQL 调优需要掌握的知识
数据库·sql