tl;dr
Since Rails
6+
you can usebefore?
andafter?
to check if a date/time is before or after another date/time.
Example
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! :(
Hint
If you want to check if a date/time is between to other dates/times, you can use
between?
Show archive.org snapshot .
Info
Technically
before?
andafter?
are only aliases for:<
and:>
, for details see here Show archive.org snapshot .
Posted by Julian to makandra dev (2022-09-08 11:52)