golang 获取月份数据
获取每个月第一天
func MonthDay(monthAt time.Time) (firstDay, lastDay string,totalDays int) {
firstDay = monthAt.AddDate(0, 0, -monthAt.Day()+1).Format("2006-01-02")
lastDay = monthAt.AddDate(0, 1, -monthAt.Day()).Format("2006-01-02")
totalDays = monthAt.AddDate(0, 1, -monthAt.Day()).Day()
return
}
mysql 获取月份数据
mysql> select curdate(),date_format(curdate(),'%Y-%m-01') as first_day,
last_day(curdate()) last_day,
day(last_day(curdate())) total_days;
+------------+------------+------------+------------+
| curdate() | first_day | last_day | total_days |
+------------+------------+------------+------------+
| 2022-09-02 | 2022-09-01 | 2022-09-30 | 30 |
+------------+------------+------------+------------+
1 row in set (0.00 sec)
版权声明:本文为default7原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。