Nisanio Nisanio - 6 months ago 7
Ruby Question

How calculate the day of the week of a date in ruby?

How calculate the day of the week of a date in ruby? For example, October 28 of 2010 is = Thursday

Answer

I have used this because I hated to go to the Date docs to look up the strftime syntax, not finding it there and having to remember it is in the Time docs.

require 'date'

class Date
  def dayname
     DAYNAMES[self.wday]
  end

  def abbr_dayname
    ABBR_DAYNAMES[self.wday]
  end
end

today = Date.today

puts today.dayname
puts today.abbr_dayname