【问题标题】:how to display the date between the from and to range of date in php如何在php中显示从日期范围和到日期范围之间的日期
【发布时间】:2014-10-28 06:35:18
【问题描述】:

如何显示从28-10-201401-11-2014 的日期范围?

28-10-2014
29-10-2014
30-10-2014
31-10-2014
01-11-2014

【问题讨论】:

  • 所以您希望能够在给定范围内打印一系列日期,对吧?
  • 你有没有尝试过?
  • 是的,我尝试在 strtotime 中转换从和到日期并尝试递增

标签: php arrays date echo


【解决方案1】:

试试这个:

<?php 
$begin = new DateTime('28-10-2014');
$end = new DateTime('01-11-2014');

$daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);

foreach($daterange as $date){
    echo $date->format("m-d-Y");
}

?>

【讨论】:

  • 这里没有打印结束日期
  • 10-28-2014 10-29-2014 10-30-2014 10-31-2014 仅打印
  • @RajaManickam 将 $datarange 替换为 $daterange = new DatePeriod($begin, new DateInterval('P1D'), $end-&gt;modify( '+1 day' ));
  • 不客气...请接受它作为答案,以便对其他人有用。
【解决方案2】:
<?php
$date = "10-28-2014";
$date1 = str_replace('-', '/', $date);
$iterations = 4;
for ($i=0 ; $i<=  $iterations ; $i++) {
  $tomorrow = date('d-m-Y',strtotime($date1 . "+$i days"));
  echo '<br/>'.$tomorrow;
}
?>

希望这行得通。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-07
    • 2017-12-20
    • 2022-11-02
    • 2011-05-11
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多