Page 1 of 1

How to iterate over days?

Posted: Sun Apr 01, 2007 3:35 am
by Thresher
I want an iterator that will generate:
January 1, 1970,
January 2, 1970,
and so on…

In Oracle’s SQL, you can iterate over a range of days using the NEXT_DAY() or apply arithmetic operators to dates. Are there any similar functions in PHP?

You may think that since a day has 86400 seconds, that you can just use the multiples of 86400. There are a few problems with this approach but the killer is that leap seconds are necessary to keep UNIX time in synchronization with the Earth’s rotation. Don’t believe me? See http://en.wikipedia.org/w/index.php?tit ... ntable=yes. Therefore, there are lots of days, like March 5, 2007, whose UNIX time is not a multiple of 86400.

I want a set of functions where I don’t need to worry about leap years with February 29. If I have a date that says “February 28” for some year, I can just ask the iterator for the next date, and it will figure out if there is a leap year to worry about.

Any suggestions?

Thanks.

Posted: Sun Apr 01, 2007 5:21 am
by Kieran Huggins

Code: Select all

$tomorrow = strtotime('February 28, 2007 +1 day');

Thank you

Posted: Sun Apr 01, 2007 11:50 am
by Thresher
Thanks Kieran Huggins. That is exactly what I need.