如何实现数据库以时间段为条件来查询

1.使用日期格式化来查询

<if test="expense.begintime!=null and expense.begintime!=''">
    <if test="expense.endtime!=null and expense.endtime!=''">
        and DATE_FORMAT(addtime,'%Y-%m-%d')>=#{expense.begintime}
        and
        DATE_FORMAT(addtime,'%Y-%m-%d')&lt;=#{expense.endtime}
    </if>
</if>

2.通过拼接字符串来查询

select * from viewfileInfo where empname like '%%'
and filename like '%%' and empid=3
and posttime>='2023-08-22 00:00:00' and posttime<='2023-08-22 23:59:59'

你可能感兴趣的:(数据库)