Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get week day name in Ruby

Tags:

ruby

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
like image 426
John Smith Avatar asked Mar 31 '15 09:03

John Smith


1 Answers

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

like image 110
shivam Avatar answered Oct 18 '22 12:10

shivam