生成一个mysql BETWEEN子句以在日期范围内查找
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了生成一个mysql BETWEEN子句以在日期范围内查找相关的知识,希望对你有一定的参考价值。
requires Rails libraries. could be rewritten to just use core Ruby libs, but I'm too lazy right now and I use this entirely in my Rails apps.
range_start = (Date.parse(start_date.to_s) - 1.day).strftime("%Y-%m-%d 23:59:59") range_end = (Date.parse(end_date.to_s) + 1.day).strftime("%Y-%m-%d 00:00:00") "#{col_name.to_s} BETWEEN '#{range_start}' AND '#{range_end}'" end
以上是关于生成一个mysql BETWEEN子句以在日期范围内查找的主要内容,如果未能解决你的问题,请参考以下文章
MySQL 用 BETWEEN AND 日期查询包含范围边界