What is the best way to query the date and time fields for date fields?

I just want to know what you do when you have a datetime field, i.e.

Game.first.starts_at
=> Thu, 03 Dec 2009 20:20:00 EST -05: 00

And you want to request it in the date field:

3.days.from_now.to_date.to_s (: db)
=> "2009-12-03"

I am currently doing this work with an operator BETWEEN, but I would like to know more approaches to solve this problem. Thanks in advance.

+1
source share
1 answer

I am not worried about the conversion date.to_s(:db). Working with clean Dateand Datetimegreat for me.

Game.first(:conditions => ["starts_at <= ?", 3.days.from_now.to_date])
+1
source

Source: https://habr.com/ru/post/1725669/


All Articles