1.最简单的方式就是前端传参1 2 3 4 5月份的数字,后台直接用sql中的函数处理
2.
3.
4.
5.
sql
#根据时间查询指定月份的数据 需要前端传值 1 2 3 4 5 6 7 9 10 11 12传递月份数字就行,后端通过sql函数计算
select * from teacher where MONTH(gmt_create)=3 and year(gmt_create)=year(now())
#mysql中不写年月日也可以查询出指定后面的时分秒
select * from teacher where gmt_create BETWEEN '2023-3-22 00:00:00' and '2023-3-22 11:00:00'
#查询指定某一天的数据 思路:先通过函数将日期格式转换为年月日格式 然后直接等于就行了
select * from teacher where DATE_FORMAT(gmt_create,'%Y-%m-%d')='2023-03-22'
#获取年月日格式的数据
select DATE_FORMAT(gmt_create,'%Y-%m-%d'),CURRENT_DATE(),DATE(now()) from teacher
6.数据库常见的日期类型都是可以识别的2012-12-12 2012.12.12 -和.都可以