Rails 3 Day of the Week Search

I am trying to create my own calendar because I cannot get any help on the calendar of events, so I am trying to do this. Show the day of the week, that is .. January 1, 2011 - Saturday, there is an easy team to get this day or I need something else

+55
ruby-on-rails-3
Jan 30 '11 at 17:58
source share
5 answers

Can you use time.wday , 0 = sunday, etc.

+110
Jan 30 2018-11-18T00:
source share

You can also get a string, such as "environment", using time.strftime ("% A")

+142
Dec 19 '12 at 21:31
source share

If you are trying to write your own calendar from scratch and want to write a function for day searching, you can check out the Conway Doomsday Algorithm , which is an interesting method for determining the day of the week on any given date. Otherwise, the standard time class has the wday method, which returns a number from 0 to 6 (0 is Sunday, 1 is Monday, etc.).

+4
Jan 30 '11 at 18:07
source share

We can use Time.now.utc.wday to get the day of the week excluding the zone.

+3
Nov 19
source share

Active use in Rails 4 - should also in most other versions ...

Both of these parameters will give you the day string (for example, "Saturday") on the specified date:

Certain date:

Date.new(2011, 1, 1).strftime('%A') # returns "Saturday" 

Today:

 Date.today.strftime('%A') 
+1
Feb 07 '18 at 20:09
source share



All Articles