in reply to How Many Days in the Past?

a) it looks like you are converting today's date into year month day, then using timelocal... you realize time() returns the epoch seconds?

b) month from localtime is actually 0 based, i.e. january is month 0. So you need to add one or it will be wrong in your code... that may very well be your problem.

Update point a... or are you using that to get midnight, of today? in any case you need to add one to the month :)
                - Ant