Slicing and dicing timestamps by month, week, day, etc

I’m trying to finish up a comp lab sign-in app in RoR that includes a db
table logging each visit with a timestamp. I want to be able to loop
through the visits table and get a weekly or monthly array and print a
table of the last four weeks listing a count for the number of visits
each day. I’ve got it working alright but it’s pretty ugly…overcoded.

Does anyone know of any similar open source code out there I could get
some ideas from??