I have a date in the following format: "%d-%m-%Y"
(for example, today's date would be 07-09-2015
), and I want to see if it is within the past seven days. Can anyone recommend a way?
You can do it like this:
require "date"
Date.today - 7 <= Date.parse("07-09-2015", "%d-%m-%Y")
sawa's answer is correct but In rails you can also check like this:
7.days.ago <= Date.parse("07-09-2015", "%d-%m-%Y")
#=> true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With