Ruby - Manipulating Time/DateTime by the Hour/Day?

Posted by viatropos on Stack Overflow See other posts from Stack Overflow or by viatropos
Published on 2010-06-16T06:24:55Z Indexed on 2010/06/16 6:32 UTC
Read the original article Hit count: 206

Filed under:
|
|

Where can I find some examples on how to manipulate the time objects by days/hours/etc?

I would like to do this:

time.now_by_hour #=> "Tue Jun 15 23 MST 2010"
time.now_by_day #=> ""Tue Jun 15 MST 2010"
time.now_by_hour - 4.weeks - 3.days #=> "Sat May 15 MST 2010"

What is the recommended order of operations? The reason for this is I would like to run through lists of times and sort them by date to the hour, not to the minute and second.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about datetime