PHP is programming language widly used for web development. In this article you will learn about creating loop which will go through all dates between two given dates.

PHP Loop Between Two Dates:

PHP Script to create a loop which navigate between 2 given dates. This script can be useful at many places where application’s required to use ranges of dates.

<?php
date_default_timezone_set('UTC');

$start_date = '2015-01-01';
$end_date = '2015-06-30';

while (strtotime($start_date) <= strtotime($end_date)) {
    echo "$start_daten";
    $start_date = date ("Y-m-d", strtotime("+1 days", strtotime($start_date)));
}

?>

PHP Loop Between Two Dates with Alternate Dates:

PHP Script to create a loop which navigate between 2 given dates with alternate dates. It means if starting date is Jan 1, then next dates will be at Jan 3, Jan 5 and so on.

<?php
date_default_timezone_set('UTC');

$start_date = '2015-01-01';
$end_date = '2015-06-30';

while (strtotime($start_date) <= strtotime($end_date)) {
    echo "$start_daten";
    $start_date = date ("Y-m-d", strtotime("+2 days", strtotime($start_date)));
}

?>

PHP Loop Between Two Dates with Day Name:

Also if you are required to find the Day on that dates , you can use following php script which will print day name in 3 digits for corresponding date.

<?php
date_default_timezone_set('UTC');

$start_date = '2015-01-01';
$end_date = '2015-06-30';

while (strtotime($start_date) <= strtotime($end_date)) {
    $timestamp = strtotime($start_date);
    $day = date('D', $timestamp);
    echo "$start_date" . "  $dayn";
    $start_date = date ("Y-m-d", strtotime("+1 days", strtotime($start_date)));
}

?>

To learn more about date time visit http://php.net/manual/en/book.datetime.php