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

相关推荐
smilejingwei5 小时前
时间列转行再转置为新交叉表
sql·sqlazy·ai写sql·可信sql
泡海椒5 小时前
JQuick-SQL 与关系型数据库集成:应用层读取后注册查询
数据库·sql
程序员塔塔喵6 小时前
【MySQL篇|第二篇】慢SQL及其优化手段
sql·mysql·慢sql优化
Warolitbos8 小时前
【数据库】SQL进阶15题,窗口函数/索引/事务一页速查
数据库·sql·学习·mysql·面试
从零数据分析9 小时前
零基础学SQL 23:和上月比总对不上?LAG/LEAD 一步取出上一次(附 4 个模板)
java·数据库·sql·mysql·oracle·sqlite·database
弦儿10 小时前
后端 Web 实战:员工管理模块(多表关系 + 多表查询 + 分页查询 + 条件分页)
后端·sql
Pniubi12 小时前
事务(Spring&MySQL)
数据库·sql·spring
云贝贝贝13 小时前
白天稳如狗半夜就抖:OceanBase 合并转储把读写延迟顶了上去
数据库·sql·oceanbase
冰暮流星14 小时前
sql之日期函数
数据库·sql
凤凰院凶涛QAQ14 小时前
《MySQL内核拆解:从SQL到InnoDB》(一) : 数据库基础&库操作&数据类型
数据库·sql·mysql