sql常见的日期函数
| 数据库 | 函数名称 | 功能描述 |
|---|---|---|
| mysql | now() | 返回当前日期和时间 |
| mysql | curdate() | 返回当前日期 |
| mysql | curtime() | 返回当前时间 |
| mysql | date_add(date,interval exprunit) | 日期加法 |
| mysql | datediff(日期1,日期2) | 返回两个日期之间的天数差 |
| mysql | date_format(date,format) | 将日期和时间格式转为指定的字符串 |
| mysql | str_to_date(str,format) | 将字符串转为日期 |
比如
sql
select now();
select curdate();
select curtime();
select current_date() as result1,now() as result2 ,curtime() as result3;
select * from products where date_format(create_at,'%Y-%m-%d') = '2024-05-19';