in reply to speed issues

How slow is too slow? If you only have to run this program once a month (you are looking at the data for the last 30 days), is it really necessary it finishes in a few seconds? I would have it started once a month as a cron-job during the night and even if it runs a few hours, I will still find its results when I start in the morning.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James