[RUBY] [Rails] Search method when date and time have each column

Search method when date and time have each column

Make a note of the search method when the date and time are stored in the DB as character strings.

start_datetime = '2020/12/22 23:35'
scope = Post.all

start_date, start_time = start_datetime.split(' ')
#Extract after the corresponding date
scope = scope.where('start_date >= ?', start_date)
# start_Remove non-applicable times when dates are equal
scope = scope.where.not('start_date = ? AND start_time < ?', start_date, start_time)

reference

Recommended Posts

[Rails] Search method when date and time have each column
[Rails] Precautions when comparing date and time with DateTime
Date and time
Date and time acquisition method using DateAndTime API
Change date and time to Japanese notation in Rails
Usability of date and time classes in each language
[Rails] require method and permit method
Rails "render method" and "redirect method"
[Rails] Save start time and end time
Explanation of Ruby Time and Date objects
[Rails] [Memo] When to add = to <%%> and when not
Rails migration column changes and so on.
[Rails] Method summary for conversion / verification / search