Reputation: 8961
Is there a way to convert a numerical date to a weekday without writing a calendar? I want to go from: "11/01/2015"
to "Sun 11"
.
Upvotes: 0
Views: 75
Reputation: 118261
Here is a way
[arup@ruby]$ irb
>> require 'date'
=> true
>> Date.strptime("11/01/2015", "%d/%m/%Y")
=> #<Date: 2015-01-11 ((2457034j,0s,0n),+0s,2299161j)>
>> Date.strptime("11/01/2015", "%d/%m/%Y").strftime("%a %d")
=> "Sun 11"
Upvotes: 5
Reputation: 18804
Consider this:
>> require 'date'
=> true
>> Date.parse("11/01/2015").strftime("%a %d")
=> "Sun 11"
Upvotes: 0