Date check

Hi guys I have a problem validating the date if it is not correct. If I search for a database entry for Feb 31st, it shows me an error on the server and it doesn't display anything. I don't know what to do, please ...

my code for storing my hash date @start = "#{params[:start][:day]}-#{params[:start][:month]}-#{params[:start][:year]}"

and for passing is `@start_date = Date.parse (@start)

`and it returns immediately upon detecting that the past date is incorrect, and this prevents me from verifying it.

+1


source to share


2 answers


Date.parse raises an ArgumentError if you pass in an invalid date such as February 31st. You can save this error if you want to answer it instead of stopping it from running. It might be preferable to do a health check before trying to parse the date in the first place.



+5


source


There's not a very good date check built into rails. You might want to try Jonathan Viney's "validates_date_time".



found here: http://svn.viney.net.nz/things/rails/plugins/validates_date_time/

+1


source







All Articles