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

相关推荐
七夜zippoe9 小时前
DolphinDB SQL查询:从基础到进阶
数据库·sql·进阶·聚合·dolphindb
爪洼传承人11 小时前
AI工具MCP的配置,慢sql优化
android·数据库·sql
Aloudata11 小时前
PL/SQL 存储过程血缘解析指南:攻克数据治理的「最后堡垒」
数据库·sql·数据治理·数据管理·元数据·数据血缘
zgscwxd13 小时前
B审批流程与数据库设计要点
sql
椰猫子13 小时前
数据库(数据库相关概念、MySQL数据库、SQL(DDL、DML、DQL))
数据库·sql·mysql
喵了几个咪14 小时前
MySQL 运维实战:ibd 文件批量转换为 SQL 完整指南(基于 ibd2sql)
运维·sql·mysql
CappuccinoRose14 小时前
关系数据库标准语言(SQL)- 软考备战(三十一)
数据库·sql·软考
山峰哥15 小时前
解锁SQL优化新境界:从索引策略到高效查询实战
数据库·sql·oracle
野生技术架构师15 小时前
从两套系统到一条 SQL:SelectDB search() 搞定日志的搜索与分析
数据库·sql
一只大袋鼠16 小时前
JDBC 详细笔记:从基础 API 到 SQL 注入解决
数据库·笔记·sql·mysql