user2993178 user2993178 - 5 months ago 9
Ruby Question

How to verify if a date has expired/passed?

I have a column of dates in the format dd mmm'yy (ex: 26 Jun'17).These dates have to be checked if they are expired using Ruby.How can i do that?

Thanks!

Answer
d = "26 Jun'17"
#⇒ "26 Jun'17"
▶ Date.today >= Date.parse(d.tr("'", ' '))
#⇒ false

Date#parse understands “26 Jun 17”:

▶ Date.parse d.tr("'", ' ')
#⇒ #<Date: 2017-06-26 ((2457931j,0s,0n),+0s,2299161j)>