目录
- current_timestamp()获取当前时间
- unix_timestamp()获取当前时区的UNIX时间戳
- from_unixtime()时间戳转日期函数
- unix_timestamp(string date)日期转时间戳函数
- 提取日期中的年月日时分秒
- weekofyear (string date)日期转周函数
- 日期比较函数datediff(string enddate, string startdate)
- 日期增加/减少函数
current_timestamp()获取当前时间
select current_timestamp();
输出:2023-11-23 11:31:31.531
unix_timestamp()获取当前时区的UNIX时间戳
select unix_timestamp();
输出:1700710598
from_unixtime()时间戳转日期函数
select from_unixtime(1700710598);
输出:2023-11-23 11:36:38
unix_timestamp(string date)日期转时间戳函数
select unix_timestamp('2023-11-23 11:36:38');
输出:1700710598
提取日期中的年月日时分秒
> select year(current_timestamp());
输出:2023
select month(current_timestamp());
输出:11
select day(current_timestamp());
输出:23
select hour(current_timestamp());
输出:13
select minute(current_timestamp());
输出:39
select second(current_timestamp());
输出:25
weekofyear (string date)日期转周函数
select weekofyear(current_timestamp());
输出:47
日期比较函数datediff(string enddate, string startdate)
select datediff(current_timestamp(),'2023-11-20');
输出:3
日期增加/减少函数
date_add(string startdate, int days)
date_sub (string startdate, int days)
select date_add(current_timestamp(),3);
输出:2023-11-26
select date_sub(current_timestamp(),3);
输出:2023-11-20