I need to parse a date from excel file, it's in format 14-3-17
because excel changes it to that...
What is the best way to parse it to a valid date?
'14-03-17'.to_date #=> Sat, 17 Mar 0014
I need to parse a date from excel file, it's in format 14-3-17
because excel changes it to that...
What is the best way to parse it to a valid date?
'14-03-17'.to_date #=> Sat, 17 Mar 0014
You can use Date.strptime to parse as well as format the parsed date, take a look here to find the list of formatting options available.
Here's an example:
Date.strptime("14-03-17", "%d-%m-%y")
=> Tue, 14 Mar 2017
Goodluck.
Use Date.parse
:
Date.parse('14-3-17'.split('-').reverse.join('-'))
#=> Tue, 14 Mar 2017