我的From和Two之间的日期列表
<?php
$scheduleStartDate = 2015-06-20;
$scheduleEndDate = 2015-06-25;
$Date = getDatesFromRange($scheduleStartDate,$scheduleEndDate);
$Date = substr($Date, 0, -1);
function getDatesFromRange($start, $end){
$dates = array($start);
$Value = '';
while(end($dates) < $end)
{
$dates[] = date('Y-m-d', strtotime(end($dates).' +1 day'));
$Value .= '"'.date('j-n-Y', strtotime(end($dates).' +1 day')).'",';
}
return $Value;
}
?>
我将它传递到我拥有的脚本中,$ Date是我从php文件中获取的那个
<script>
$( window ).load(function() {
var availableDates = [<?php echo $Date?>];
function available(date) {
dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
if ($.inArray(dmy, availableDates) != -1) {
return [true, "","Available"];
} else {
return [false,"","unAvailable"];
}
}
$('#date').datepicker({
beforeShowDay: available,
currentText: "Now",
dateFormat: 'yy-mm-dd',
inline: true,
altField: '#datepicker_value',
onSelect: function(){
getData();
}
});
});
</script>
最后我在日期选择器中启用了日期但是它在统计时间延迟2天,在结束时额外增加1天如果我的日期从20日到25日将启用22日至26日的日期 任何帮助可能会大大减少。
答案 0 :(得分:1)
试试这个PHP代码:
<?php
$scheduleStartDate = '2015-06-20';
$scheduleEndDate = '2015-06-25';
$Date = getDatesFromRange($scheduleStartDate, $scheduleEndDate);
$Date = substr($Date, 0, -1);
function getDatesFromRange($start, $end){
$startDate = new DateTime($start);
$endDate = new DateTime($end);
$endDate->modify('+1 day');
$daterange = new DatePeriod($startDate, new DateInterval('P1D'), $endDate);
$result = '';
foreach($daterange as $date){
$result .= '"'.$date->format("j-n-Y").'",';
}
return $result;
}
?>