当前位置:网站首页>Sql查询时间段内容

Sql查询时间段内容

2022-06-26 05:34:00 杰拉德·皮克·谢

Sql查询时间段内容

思路

  • 前端传来某个时间段 startTime(String )- endTime(String ) 格式为天不包含时分秒
  • 在书写sql 是在对应字段加上时间格式 DATE_FORMAT(crh.create_time,'%Y-%m-%d') 年月日(可自由定义)
  • 查询结果:例如 2022-6-8 到2022-6-10的时间段
  • 结果包含 6-8 0点到 6-10号 59分59秒

sql

       select * from u_user where 1=1
        <if test="user.endTime != null and user.endTime != '' and user.startTime != null and user.startTime != ''">
            and DATE_FORMAT(crh.create_time,'%Y-%m-%d') &gt;=#{
    user.startTime}
            and
            DATE_FORMAT(crh.create_time,'%Y-%m-%d') &lt;=#{
    user.endTime}
        </if>
原网站

版权声明
本文为[杰拉德·皮克·谢]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_44684812/article/details/125338348