ruby - Use DateTime to print name of day from a date? -


I am trying to use date time to go through a list of dates, and weekdays (Monday, Tuesday, Wednesday, & Amp; c) which are often associated with each date in the list.

I'm trying this:

  content = CSV.open 'event_attendees.csv', header: true, header_converter :: icon content. Line | Time = content.map {| Line | Line [: regdate]} target_days = hash [times.group_by {| T | DateTimeTermMem (T, '% M /% D /% Y% H:% M') Wday} .map {| K, V [K, v.count]} Sort_by {| K, v | V} .reverse] puts target_days   

I get:

  {1 = 6; 2 = & gt; 5, 5 = & gt; 4, 6 = & gt; 2, 0 = & gt; 1}   

What do I think that every day is 0 (Sunday), 1 (Monday) & amp; How can I change this day as a real name? Or how can this short name (Sun, Mon, Mars, and C.) be changed?

Besides, I am not positive, I am returning the right day on the day. Looking at my list, there are six dates for 11/12/2008 November 12, 2008 was a Wednesday ???? But it seems like it is showing that the biggest day of 6 days is Monday. So, I'm not sure that it's really counting the right day of the week.

Can someone please explain what I am doing, do not count the exact day of week? How to change it in the form of day and short name?

Thank you!

You wday integer date :: DAYNAMES Can be converted into full names and can change the abbreviation by using date :: ABBR_DAYNAMES : date :: DAYNAMES [3] # = & Gt; "Wednesday" Date: ABBR_DAYNAMES [3] # = & gt; As far as your algorithm goes, it looks right to me:

    code> requires "date" bar = ["4/25/2014 00:00 ", # Friday" 4/21/2014 00:00 ", # Monday" 4/22/2014 00:00 ", # Tuesday" 4/20/2014 00:00 ", # Sunday" 4/22 / 2014 00:00 ", # Tuesday" 4/21/2014 00:00 ", # Monday" 4/21/2014 00:00 ", # Monday" 4/19/2014 00:00 "] # Saturday Target_day = Hash [times.group_by | Time | DateTime.STRUTMENT (time, "% m /% d /% Y% H:% M") Wday end.map do | Key, value | [Date: ABBR_DAYNAMES [Key], Value. Data] end.sort_by | Key, value | Value end.reverse] puts_s # target_days = & gt; = "Gtc: P> I will double check the content of the file, and then take action through the algorithm to see the mistake.   

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -