/ Published in: Rails
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def mysql_date_compare(start_date, end_date, col_name = :created_at) 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