Forum Moderators: coopster

Message Too Old, No Replies

PHP Date Question

Generate dates between 2 given dates

         

scorpio

6:16 am on Jul 13, 2004 (gmt 0)

10+ Year Member



is there a way to generate the dates that are between 2 given dates.

for ex: generating all the dates that are between 2004-07-14 to 2004-08-04?

johnerazo

7:46 am on Jul 13, 2004 (gmt 0)

10+ Year Member



Convert the 2 dates into a Unix timestamps using strtotime() and get their difference. Convert the difference to the number of days offset by dividing the difference by (24*60*60).

Through a loop, constantly add x days from the starting date until you reach the exact number of days offset using strtotime()
eg.
1st pass - strtotime("2004-07-14 +0 day")
2nd pass - strtotime("2004-07-14 +1 day")
3rd pass - strtotime("2004-07-14 +2 day")
4th pass - strtotime("2004-07-14 +3 day")

scorpio

12:53 pm on Jul 13, 2004 (gmt 0)

10+ Year Member



thnx for the reply, john

i've sorted it out.

i used mktime to find the no. of days between the 2 dates and then used another mktime within a loop, where the day gets incremented.