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

相关推荐
拾起零碎39 分钟前
U8/用户权限合并查询
sql
大卫小东(Sheldon)1 小时前
SQL查询中的窗口函数(主要以 PostgreSQL 为例)
大数据·sql·postgre
SadSunset1 小时前
(15)动态SQL中的if,foreach和一些其他的常用标签
数据库·python·sql
宝桥南山2 小时前
Azure - 尝试使用一下Kusto Query Language(KQL)
sql·microsoft·微软·database·azure·powerbi
云闲不收2 小时前
hive和hadoop如何部署
数据仓库·hive·hadoop
TT哇2 小时前
关闭外键约束检查
数据库·sql·oracle
2501_916766542 小时前
MySQL 数据库与 SQL 语言介绍
数据库·sql·mysql
Hello.Reader2 小时前
在 Flink SQL 里做向量检索 VECTOR_SEARCH
大数据·sql·flink
卿雪19 小时前
Redis 线程模型:Redis为什么这么快?Redis为什么引入多线程?
java·数据库·redis·sql·mysql·缓存·golang
QQ 19226381 天前
采用整数规划的光储调度:光伏储能优化调度探究
sql