一、随机示例(想到哪里写哪里)
1.系统时间函数
查询
sql
select
current_timestamp --当前格式化时间
,current_date --当前格式化日期
,unix_timestamp() --当前unix时间戳
结果:

2.时间函数转换
查询
sql
--将时间戳转化为格式化时间
select
from_unixtime(1725865044)
,from_unixtime(1725865044,'yyyy-MM-dd')
,from_unixtime(1725865044,'yyyy-MM')
,from_unixtime(1725865044,'dd')
结果

查询
sql
--时间格式化为日期
select to_date('2024-09-09 14:57:24')
结果

查询
sql
--日期格式化
select
date_format('2024-09-09 14:57:24','yyyy-MM-dd')
,date_format('2024-09-09','yyyy-MM')
,date_format('2024-09-09','yyyy')
结果

3.时间函数
查询
sql
select
year(current_date) --年
,quarter(current_date) --季度
,month(current_date) --月
,day(current_date) --日
,hour(current_timestamp) --时
,minute(current_timestamp) --分
,second(current_timestamp) --秒
结果
