<input type = "date" name = "myDate" onchange = ""> //this is input date
当用户选择日期时,它希望根据上述日期进行更改 如何根据指定日期更改请帮助我..!
<table class="table table-bordered" id="thbg">
<thead><td></td>
<th>Project</th>
<th>Activity</th>
<th>Bill Type</th>
<?php
$day = "1";
$month = "11";
$year = "2017";
$start_date = $day."-".$month."-".$year;
$start_time = strtotime($start_date);
$end_time = strtotime("+1 week", $start_time);
for($i=$start_time; $i<$end_time; $i+=86400)
{
print '<th align="center"> '. date("m-d-Y l", $i). '</th>';
}
?>
<th>Hours</th>
</thead>
</table>
输出也是错误的日期,例如我一次得到两个星期天
有人可以建议解决方案吗?
答案 0 :(得分:1)
不确定您在此尝试实现的目标,但更好的选择是使用DateTime
类
类似的东西应该起作用
$day = "1";
$month = "11";
$year = "2017";
$objDateStart = DateTimeImmutable::createFromFormat('j-m-Y', $day."-".$month."-".$year);
$objDateEnd = $objDateStart->modify('+1 week');
$objDateRange = new DatePeriod($objDateStart, new DateInterval('P1D'), $objDateEnd);
foreach($objDateRange as $objDate)
{
echo '<th align="center"> '. $objDate->format("m-d-Y l"). '</th>';
}
答案 1 :(得分:0)
As it is i have executed your code, i am getting proper output without any repeated values.
echo "<table><thead>
<th>Project</th>
<th>Activity</th>
<th>Bill Type</th>";
$day = "1";
$month = "11";
$year = "2017";
$start_date = $day."-".$month."-".$year;
$start_time = strtotime($start_date);
$end_time = strtotime("+1 week", $start_time);
for($i=$start_time; $i<$end_time; $i+=86400)
{
print '<th align="center"> '. date("m-d-Y l", $i). '</th>';
}
echo "<th>Hours</th>
</thead>";
答案 2 :(得分:0)
date
命令重复11月5日,因为这是夏令时,它将小时数缩小到00:00:00。
请尝试使用datetime
对象。
这是一个循环播放日期范围的答案。