Reputation: 3590
I have a date object in Rails, which I'd like to format.
I've made it this far:
delivery_time.date.strftime("%w, %d/%m/%Y")
I'd like it to print out 'Wednesday, 04/01/2012'
Is there a quick method to change the '%w' into 'Wednesday'?
Upvotes: 22
Views: 24008
Reputation: 2087
I know the OP wanted the string for the weekday, but if for whatever reason you are doing something more algorithmic and need a numerical representation, you can use cwday on the Date object
d = Date.new(2017,7,26)
d.cwday
#=> 3
Monday is 1
Upvotes: 7
Reputation: 3621
Date.today.strftime("%A")
=> "Wednesday"
Date.today.strftime("%A").downcase
=> "wednesday"
Upvotes: 15
Reputation: 8807
%A
gives you day of the week.
strftime("%A, %d-%m-%Y")
will give you:
Wednesday, 04-01-2012
Upvotes: 4
Reputation: 2213
Yes, you can use "%A" for the full day name.
See also http://pubs.opengroup.org/onlinepubs/007908799/xsh/strftime.html
Upvotes: 2
Reputation: 9481
Looking at the Ruby docs for strftime
Time.now.strftime("%A, %d/%m/%Y")
=> "Wednesday, 04/01/2012"
The %A
character is the full day name.
Upvotes: 24
Reputation: 28245
try %A
instead of %w
delivery_time.date.strftime("%A, %d/%m/%Y")
Upvotes: 1