how to code a condition: 'can this string be converted into a date type'? (ruby) -


Can I code this condition in some way in Ruby? I need to know the if any string can be converted to a date , the only way to do this is date.parse ("my string") and the exception is there any other way?

  date_scraped_from_the_net = "20 December 2009" or "Today" if date_scraped_from_the_net is not of date type need_to_be_updated = true end  

If you need a sophisticated date parsing, I will try.

However, if I understand your specific question, you would like to use Rescue to conditionally use methods to increase errors:

  if (date.parse (date_scraped_from_the_net) salvage zero) need_to_be_updated = true end  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -