views:

52

answers:

2

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.

+1  A: 

You chould check out active_support gem for this. It has nifty time/date manipulation methods so you can do stuff like this:

Time.now - 3.weeks - 2.days - 5.hours - 35.minutes
Eimantas
+1  A: 

Time.strftime (docs) ?

demas
Now it makes me wonder if viatropos wanted manipulation of string representation or of the date/time itself .)
Eimantas