mysql中查询两个时间之间 - Go语言中文社区

mysql中查询两个时间之间


类似于这样,要查询2个时间之间的数据, 时间作为查询条件,可传可不传,可传1个,可传2个.

  <if test="map.beginCreatetime != null and map.beginCreatetime != ''">
            and DATE_FORMAT(a.create_time, '%Y-%m-%d %H:%i:%S') &gt;= DATE_FORMAT(#{map.beginCreatetime}, '%Y-%m-%d %H:%i:%S')
        </if>
        <if test="map.endCreatetime != null and map.endCreatetime != ''">
            and DATE_FORMAT(a.create_time, '%Y-%m-%d %H:%i:%S') &lt;= DATE_FORMAT(#{map.endCreatetime}, '%Y-%m-%d %H:%i:%S')
        </if>

时间戳转时间,再比较

    <if test="beginCreatetime != null and beginCreatetime != ''">
            and FROM_UNIXTIME(a.regtime) &gt;= #{beginCreatetime}
        </if>
        <if test="endCreatetime != null and endCreatetime != ''">
            and FROM_UNIXTIME(a.regtime) &lt;= #{endCreatetime}
        </if>

 

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_39940205/article/details/83865531
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 17:39:16
  • 阅读 ( 1428 )
  • 分类:数据库

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢