<?php
$start=date('2013-05-02');
$end=date('2013-05-06');
?>
我像下面一样出来了,我不知道如何得到这个请帮助我
星期四 2013-05-02 星期五 2013-05-03 星期六 2013-05-04 星期日 2013-05-05 星期一 2013-05-06
<?php
$start=date('2013-05-02');
$end=date('2013-05-06');
?>
我像下面一样出来了,我不知道如何得到这个请帮助我
星期四 2013-05-02 星期五 2013-05-03 星期六 2013-05-04 星期日 2013-05-05 星期一 2013-05-06
$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>";
}
注意[仅支持5.3.0 php版本以上]
调整此处找到的答案,您可以很容易地做到这一点。
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>';
这对你有用
<?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
看一下这个,
<?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>";
}
?>