Okay say I have two timestamps saved in database in the format yyyymmdd, a start date and end date.
say these are my start and end dates: 20110618-20110630
How could i make it echo 20110618, 20110619, 20110620 etc all the way to 20110630?
Okay say I have two timestamps saved in database in the format yyyymmdd, a start date and end date.
say these are my start and end dates: 20110618-20110630
How could i make it echo 20110618, 20110619, 20110620 etc all the way to 20110630?
// Will return the number of days between the two dates passed in
function count_days( $a, $b ) {
// First we need to break these dates into their constituent parts:
$gd_a = getdate( $a );
$gd_b = getdate( $b );
// Now recreate these timestamps, based upon noon on each day
// The specific time doesn't matter but it must be the same each day
$a_new = mktime( 12, 0, 0, $gd_a['mon'], $gd_a['mday'], $gd_a['year'] );
$b_new = mktime( 12, 0, 0, $gd_b['mon'], $gd_b['mday'], $gd_b['year'] );
// Subtract these two numbers and divide by the number of seconds in a
// day. Round the result since crossing over a daylight savings time
// barrier will cause this time to be off by an hour or two.
return round( abs( $a_new - $b_new ) / 86400 );
}
// Prepare a few dates
$date1 = strtotime( '20110618' );
$date2 = strtotime( '20110630' );
// Calculate the differences, they should be 43 & 11353
echo "<p>There are ", count_days( $date1, $date2 ), " days.</p>
";
$days = count_days($date1, $date2);
for ($i = 0; $i < $days; $i++) {
echo date('Ymd', $date1+(86400*$i));
}
Using function from: Get number of days between two dates.