Zach Smith
Zach Smith

Reputation: 8961

convert numerical date to weekdays

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

Answers (2)

Arup Rakshit
Arup Rakshit

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

Jikku Jose
Jikku Jose

Reputation: 18804

Consider this:

>> require 'date'
=> true
>> Date.parse("11/01/2015").strftime("%a %d")                                                     
=> "Sun 11"

Upvotes: 0

Related Questions