Ruby on Rails: the best way to compare two dates?

Ruby on-RailsDate

Ruby on-Rails Problem Overview


I have a date variable, stored as a String in the 'YYYY-mm-dd' format. What is the best way to check, if that date has not already passed?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

Date.parse('2010-11-01') < Date.today

will return true if '2010-11-01' has already passed

Solution 2 - Ruby on-Rails

You can also use past?

Date.parse("2012-11-01").past?

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkrnView Question on Stackoverflow
Solution 1 - Ruby on-RailsDavid SulcView Answer on Stackoverflow
Solution 2 - Ruby on-RailsdanivalentinView Answer on Stackoverflow