Posted 27 days ago. Visible to the public.

Rails: Comparison of Dates - before? and after?


Since Rails 6+ you can use before? and after? to check if a date/time is before or after another date/time.


christmas = Date.parse('24.12.2022') date_of_buying_a_gift = Date.parse('12.12.2022') date_of_buying_a_gift.before?(christmas) # => true # Now you are well prepared for Christmas!! ;) date_of_buying_a_gift = Date.parse('26.12.2022') date_of_buying_a_gift.after?(christmas) # => true # Now you are too late for christmas! :(


If you want to check if a date/time is between to other dates/times, you can use between? Archive .


Technically before? and after? are only aliases for :< and :>, for details see here Archive .

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Last edit:
27 days ago
by Julian
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Julian to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more