- 使用date_format
select date_format(current_date(),'%Y年%m月')
union all
select concat(date_format(current_date(),'%Y年'),quarter(current_date()),'季度')
union all
select date_format(current_date(),'%Y年%u周')
+——————————————+
| date_format(current_date(),’%Y年%m月’) |
+——————————————+
| 2017年10月 |
| 2017年4季度 |
| 2017年43周 |
+——————————————+
- 计算周的周末日期
#求2017-12-19的下一个周日
select adddate('2017-12-19',7-date_format('2017-12-19','%w'))
本文介绍了如何使用SQL的DATE_FORMAT函数来格式化日期,并展示了如何获取当前日期的年月、季度和周信息。此外,还提供了计算指定日期所在周的周末日期的方法。

1257

被折叠的 条评论
为什么被折叠?



