Here is my IRB session
1.9.2p290 :020 > Date.strptime("31-2-2010", "%d-%m-%Y") ArgumentError: invalid date
I gave the correct values, but it returns ArgumentError. Did I miss something?
ArgumentError
Yes, something is missing for you:In February there are no 31 days, regardless of the year.
You have entered an invalid date.
Please note that Time.strptime("31-2-2010", "%d-%m-%Y")will provide you 2010-03-03 00:00:00 +0000.
Time.strptime("31-2-2010", "%d-%m-%Y")
2010-03-03 00:00:00 +0000
I use Time.strptime("31-2-2010", "%d-%m-%Y").to_dateto avoid invalid date errors.
Time.strptime("31-2-2010", "%d-%m-%Y").to_date