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

相关推荐
naumy20 小时前
sqlalchemy
sql
chimchim6621 小时前
StarRocks导入数据-使用 Broker Load 进行异步导入
大数据·sql
Lris-KK21 小时前
【Leetcode】高频SQL基础题--1341.电影评分
sql·leetcode
Qlittleboy1 天前
tp5的tbmember表闭包查询 openid=‘abc‘ 并且(wx_unionid=null或者wx_unionid=‘‘)
数据库·sql·php
markfeng81 天前
一文搞懂MySQL字符集
sql·mysql
小白不想白a1 天前
【MySQL】常用SQL语句
数据库·sql·mysql
core5121 天前
Hive实战(二)
数据仓库·hive·hadoop
蜗牛~turbo1 天前
金蝶云星空 调价表取历史价格
java·数据库·sql·c#·database
danns8881 天前
neo4j数据库创建范例(SQL文)
数据库·sql·neo4j
JAVA不会写2 天前
在Mybatis plus中如何使用自定义Sql
数据库·sql