Latest news:

New android application Islamic Video has been released. its a free islamic video application for android smartphone. Download now!

How to run foreach loop between 2 given dates ?

$begin = new DateTime( '2010-05-01' );
$end = new DateTime( '2010-05-10' );

$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);

foreach ( $period as $dt )
  echo $dt->format( "l Y-m-d H:i:s\n" );

This will output all days in the defined period between $start and $end. If you want to include the 10th, set $end to 11th. You can adjust format to your liking. See the PHP Manual for DatePeriod.

Tags : PHP,

Views : 3624

Recent Posts


Popular Tags


Subscribe Us

Follow Us