Archive for January, 2011

day_of_week in Ruby and Ruby on Rails

This wasn’t very straight forward to find, so I thought I would write something here.  To get the day_of_week in Ruby/Rails, try this:

Date::DAYNAMES[Date.today.wday]

Essentially, we could probably wrap this…

class Date  
  def day_of_week    
    Date::DAYNAMES[self.wday]  
  end
end

And once included:

ruby-1.9.2-p136 :050 > Date.today.day_of_week
=> "Saturday"

Cheers.

© 2012 - Jeff Ancel
Wordpress Themes
Scroll to Top