php – 如何找到两个指定日期之间的日期?

前端之家收集整理的这篇文章主要介绍了php – 如何找到两个指定日期之间的日期?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我有两个日期20-4-2010和22-4-2010
在两个文本框和
我想要的日期是这样的20,21,22.我该怎么做?
我很确定这已经回答了十几亿次,但无论如何:
  1. $start = strtotime('20-04-2010 10:00');
  2. $end = strtotime('22-04-2010 10:00');
  3. for($current = $start; $current <= $end; $current += 86400) {
  4. echo date('d-m-Y',$current);
  5. }

10:00部分是为了防止代码由于夏令时而跳过或重复一天.

通过给出天数:

  1. for($i = 0; $i <= 2; $i++) {
  2. echo date('d-m-Y',strtotime("20-04-2010 +$i days"));
  3. }

PHP5.3

  1. $period = new DatePeriod(
  2. new DateTime('20-04-2010'),DateInterval::createFromDateString('+1 day'),new DateTime('23-04-2010') // or pass in just the no of days: 2
  3. );
  4.  
  5. foreach ( $period as $dt ) {
  6. echo $dt->format( 'd-m-Y' );
  7. }

猜你在找的PHP相关文章