• List function

  • current_date() 当前日期

select current_date();
--2022-02-22
  • now() 或 current_timestamp() 当前时间
select now();
select current_timestamp();
--2022-02-22 22:22:22
  • datediff(endDate, startDate) 日期相差天数
select datediff('2022-02-22','2022-02-20');
--2
  • months_between(endDate, startDate) 日期相差月数
select months_between('2022-06-16','2022-02-12');
--4.12903226
  • date_add(startDate, numDays) 日期加N天
select date_add('2022-02-22',3)
--2022-02-25
 
select date_add('2022-02-22',-3)
--2022-02-19
  • date_sub(startDate, numDays) 日期减N天
select date_sub('2022-02-22',3)
--2022-02-19
 
select date_sub('2022-02-22',-3)
--2022-02-25
  • add_months(startDate, numMonths) 日期加N月
select add_months('2022-02-22',3);
--2022-05-22
 
select add_months('2022-02-22',-3);
--2021-11-22
  • last_day(date) 日期所在月份的最后一天
select last_day('2022-02-22');
--2022-02-28
  • next_day(startDate, dayOfWeek) 指定日期后的第一个星期几(星期参数为英文缩写)
select next_day('2022-02-22','MON')
--2022-02-28

reference:
原文链接:https://blog.csdn.net/mypowerhere/article/details/124118302

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐