0

Possible Duplicates:
PHP Day iterator
I have 2 dates in PHP, how can I run a foreach loop to go through all of those days?

I want to create a loop which creates records for each day from today to one year later.

There is no input for dates. From date which the form is submitted to the day 1 year after.

How can i do that ?

For example today when i submit the form today, i need a loop from 17/01/2011 to 17/01/2012

Community
  • 1
  • 1
Mustafa
  • 825
  • 3
  • 14
  • 37
  • duplicate of [Loop through all months in a date range](http://stackoverflow.com/questions/2155110/php-loop-thru-all-months-in-date-range/2155168#2155168) - same approach – Gordon Jan 17 '11 at 11:58
  • duplicate of [I have 2 dates in PHP, how can I run a foreach loop to go through all of those days?](http://stackoverflow.com/questions/3207749/i-have-2-dates-in-php-how-can-i-run-a-foreach-loop-to-go-through-all-of-those-da/3207849) – Gordon Jan 17 '11 at 11:59
  • duplicate of [how to find the dates between two dates specified](http://stackoverflow.com/questions/2736784/how-to-find-the-dates-between-two-dates-specified) – Gordon Jan 17 '11 at 12:00
  • 1
    @Gordon I get the feeling that I've seen this question before, don't you? :p – Mike B Jan 17 '11 at 12:00

2 Answers2

4

This should work

$next_year = strtotime('+1 year');
$current_time = time();

while($current_time < $next_year){
    $current_time = strtotime('+1 day', $current_time);
    print date('d-m-Y', $current_time);
}

You can then use the $current_time variable with date() to format the time in whatever way you wish.

Matt Lowden
  • 2,586
  • 17
  • 19
-1
<?php 
echo date('Y-m-d', strtotime('+1 year'));
powtac
  • 40,542
  • 28
  • 115
  • 170