I am preparing a festival site. I have a table with a datetime field for the festival dates.
Festival will be in between “6 / March / 2013″ and ” 7 / April / 2013″.
So I created the loop as in these answer here :
Schema::create('dates',function($table)
{
$table->increments('id');
$table->date('date');
$table->timestamps();
});
$starting_date = new DateTime('2013-03-06');
$ending_date = new DateTime('2013-04-06');
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($starting_date , $interval, $ending_date);
foreach($period as $dt)
{
DB::table('dates')->insert(array(
'date' => $dt
));
}
The database is filled until 4th of april , the loop does not add more than 30 days.
Can you help me to find a fix for missing days ?
ps: I used alternative while loop resulting same:
$starting_date = new DateTime('2013-03-06');
$ending_date = new DateTime('2013-04-07');
while($starting_date <= $ending_date){
DB::table('dates')->insert(array(
'date' => $starting_date
));
}
$starting_date->add(new DateInterval('P1D'));
}
Which outputs
2013-03-06
2013-03-07
2013-03-08
2013-03-09
2013-03-10
2013-03-11
2013-03-12
2013-03-13
2013-03-14
2013-03-15
2013-03-16
2013-03-17
2013-03-18
2013-03-19
2013-03-20
2013-03-21
2013-03-22
2013-03-23
2013-03-24
2013-03-25
2013-03-26
2013-03-27
2013-03-28
2013-03-29
2013-03-30
2013-03-31
2013-04-01
2013-04-02
2013-04-03
2013-04-04
2013-04-05
2013-04-06