Reputation: 308
I'm reading from xls & csv files with the dates that have the following formatting;
10-Aug-14
And I need them to be: dd/mm/yyyy (11/08/2014)
Have tried the date_format gem the standard Ruby Date & Time classes with no luck.
Inspection shows it's an array consisting of a Date object & a String;
p date_start #=> #<Date: -4712-01-01 ((0j,0s,0n),+0s,2299161j)> "11-Aug-14"
puts date_start #=> -4712-01-01
#=> 11-Aug-14
puts date_start.class #=> Array
puts date_start[0].class #=> Date
puts date_start[1].class #=> String
Any idea how I can parse this into a date that Ruby understands. Also I need to get the weekdays in numbers between two dates so getting this right is key.
Upvotes: 0
Views: 1355
Reputation: 1089
For parse date:
my_date = Date.strptime("10-Aug-14 ", "%d-%b-%y")
To the other format(dd/mm/yy):
puts my_date.strftime("%d/%m/%Y")
For weekdays count you can use 'weekdays gem' --> https://github.com/mdarby/weekdays
Upvotes: 3