我有两个html输入日期如下:
Date 1 <input class="input100" type="date" name="date" placeholder="Date in.. dd/mm/yyyy">
Date 2 <input class="input100" type="date" name="date" placeholder="Date in.. dd/mm/yyyy">
我有这个PHP代码:
$gdate = strtotime($_REQUEST['date']);
$gdate = date('Y-m-d', $gdate);
我将日期作为$gdate
放在我的数据库中,但是如何将其设置为将日期1和日期2之间的所有日期自动放入具有特定限制的数据库中,以便赢得'太过分了?
答案 0 :(得分:1)
通过:http://php.net/manual/en/class.dateperiod.php#109846
$begin = new DateTime( '2012-08-01' );
$end = new DateTime( '2012-08-05' );
$end = $end->modify( '+1 day' );
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval ,$end);
foreach($daterange as $date){
echo $date->format("Y-m-d") . PHP_EOL;
}
输出:
2012-08-01
2012-08-02
2012-08-03
2012-08-04
2012-08-05
答案 1 :(得分:0)
这对我很有帮助
function date_range($first, $last, $step = '+1 day', $output_format = 'd/m/Y' ) {
$dates = array();
$current = strtotime($first);
$last = strtotime($last);
while( $current <= $last ) {
$dates[] = date($output_format, $current);
$current = strtotime($step, $current);
}
return $dates;
}