3
<?php
$start=date('2013-05-02');
$end=date('2013-05-06');
?>

I got out put like following,I don't know how to get this please help me

Thursday 2013-05-02 Friday 2013-05-03 Saturday 2013-05-04 Sunday 2013-05-05 Monday 2013-05-06

jems peterson
  • 147
  • 1
  • 2
  • 7

4 Answers4

3
$start    = new DateTime('2013-5-02');
$end      = new DateTime('2013-6-02');
$interval = DateInterval::createFromDateString('1 day');
$period   = new DatePeriod($start, $interval, $end);

foreach ($period as $dt)
{
    echo $dt->format("l Y-m-d");
    echo "<br>";
}

Note[it's support only Above 5.3.0 php version]

fullybaked
  • 4,117
  • 1
  • 24
  • 37
Mayur Patel
  • 245
  • 1
  • 12
1

Adapting the answer found here you can quite easily do this.

function createDateRangeArray($strDateFrom,$strDateTo)
{
    // takes two dates formatted as YYYY-MM-DD and creates an
    // inclusive array of the dates between the from and to dates.

    // could test validity of dates here but I'm already doing
    // that in the main script

    $aryRange=array();

    $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2),     substr($strDateFrom,8,2),substr($strDateFrom,0,4));
    $iDateTo=mktime(1,0,0,substr($strDateTo,5,2),     substr($strDateTo,8,2),substr($strDateTo,0,4));

    if ($iDateTo>=$iDateFrom)
    {
        array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
        while ($iDateFrom<$iDateTo)
        {
            $iDateFrom+=86400; // add 24 hours
            array_push($aryRange,date('l Y-m-d',$iDateFrom));
        }
    }
    return $aryRange;
}

$start=date('2013-05-02');
$end=date('2013-05-06');

echo '<pre>'.print_r(createDateRangeArray($start, $end), 1).'</pre>';
Community
  • 1
  • 1
naththedeveloper
  • 4,503
  • 6
  • 36
  • 44
0

This will work for you

<?php
function dateRange($start, $end) {
    date_default_timezone_set('UTC');

    $diff = strtotime($end) - strtotime($start);

    $daysBetween = floor($diff/(60*60*24));

    $formattedDates = array();
    for ($i = 0; $i <= $daysBetween; $i++) {
        $tmpDate = date('Y-m-d', strtotime($start . " + $i days"));
        $formattedDates[] = date('l Y-m-d', strtotime($tmpDate));
    }    
    return $formattedDates;
}


$start='2013-05-02';
$end='2013-05-06';

$formattedDates = dateRange($start, $end);

echo join(', ', $formattedDates); 
// => Thursday 2013-05-02, Friday 2013-05-03, Saturday 2013-05-04, Sunday 2013-05-05, Monday 2013-05-06
fullybaked
  • 4,117
  • 1
  • 24
  • 37
0

Check this out,

<?php
$from_date = strtotime("2013-05-02");
$to_date   = strtotime("2013-08-02");

for ($current_date = $from_date; $current_date <= $to_date; $current_date += (60 * 60 * 24)) { // looping for avvailable dates
    // use date() and $currentDateTS to format the dates in between
    $date = date("Y-m-d",$current_date);
    $day_name = getdate($current_date) ;
    $day_name = $day_name['weekday'];

    echo $date." ".$day_name."<br>";
}   
?>
6339
  • 475
  • 3
  • 16