From: Chris Hulan Date: 2006-06-20T22:25:54+09:00 Subject: Re: Converting a date to the day of the week Kris Leech wrote: > http://www.ruby-doc.org/stdlib/libdoc/date/rdoc/classes/Date.html#M000370 > > Looking at the Date class there are two constants, a hash DAYS and an > array ABBR_DAYNAMES. > > DAYS = { 'sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday'=> 3, > 'thursday' => 4, 'friday' => 5, 'saturday' => 6 } > ABBR_DAYNAMES = %w(Sun Mon Tue Wed Thu Fri Sat) > > I can get the integer for the day 'number' (0 to 6) from a date using > the wday method, ie. Date.today.wday > But how do I use the array or hash from Date.rb, it does not appear to > be initialized at the time of use. > > Ultimately what I wish to create is a select box (monday-sunday) with > today's day pre-selected. > > I've looked for a Rails helper to this but there does not appear to be > one. > > Many thanks. AFM. irb(main):003:0> Date::ABBR_DAYNAMES[Date.today.wday] => "Tue" irb(main):004:0> Date::DAYS.index Date.today.wday => "tuesday" HTH -- Posted via http://www.ruby-forum.com/.