Here is my IRB session
1.9.2p290 :020 > Date.strptime("31-2-2010", "%d-%m-%Y") ArgumentError: invalid date
I have given the proper values, yet it is returning ArgumentError. Am I missing something here?
ArgumentError
Yes, you are missing something: There are never 31 days in February, regardless of the year.
You have given it an invalid date.
Note that Time.strptime("31-2-2010", "%d-%m-%Y") would give 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_date to avoid invalid date errors.
Time.strptime("31-2-2010", "%d-%m-%Y").to_date
Yes, you are missing something:
There are never 31 days in February, regardless of the year.
You have given it an invalid date.