How can I get the name of the day in Ruby?
For eg. something like that:
a = Date.today
a.day_name
# => Tuesday
the only thing I could find was .wday
but that only returns for the number of the day in the week
a.wday
# => 2
How can I get the name of the day in Ruby?
For eg. something like that:
a = Date.today
a.day_name
# => Tuesday
the only thing I could find was .wday
but that only returns for the number of the day in the week
a.wday
# => 2
Time.now.strftime("%A")
# => "Tuesday"
or
Date.today.strftime("%A")
# => "Tuesday"
Weekday:
%A - The full weekday name (``Sunday'')
%^A uppercased (``SUNDAY'')
%a - The abbreviated name (``Sun'')
%^a uppercased (``SUN'')
Source: strftime @ apidock.com
Since the OP references Date.today
, we can assume the presence of Date
(Rails, not pure Ruby), so a simpler solution would be to use the Date::DAYNAMES
array:
Date::DAYNAMES[Date.today.wday]