开发者

problem with comparing date in Ruby (findbySql)

开发者 https://www.devze.com 2023-01-25 07:07 出处:网络
WHERE l.created_at > #{params[:daysAgo].to_i.days.ago.strftime(\'%Y-%m-%d\')} is working correctly but

WHERE

l.created_at > #{params[:daysAgo].to_i.days.ago.strftime('%Y-%m-%d')}

is working correctly but

WHERE

l.created_at > '#{params[:daysAgo].to_i.days.ago.strftime('%Y-%m-%d 00:00')}'

is not returning any rows... can anyone help.. but for date compa开发者_如何学Gorison we should use quotes right..??


You can convert time to database one by to_s(:db)

For example,

Time.now.to_s(:db)

I found that database time is better use Time.zone in Rails

Time.zone.now.to_s(:db)
0

精彩评论

暂无评论...
验证码 换一张
取 消