加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 16:30:58 所属栏目:PHP教程 来源:网络整理
导读:如果我有两个日期20-4-2010和22-4-2010 在两个文本框和 我想要的日期是这样的20,21,22.我该怎么做? 我很确定这已经回答了十几亿次,但无论如何: $start = strtotime('20-04-2010 10:00');$end = strtotime('22-04-2010 10:00');for($current = $start; $cur
如果我有两个日期20-4-2010和22-4-2010
在两个文本框和
我想要的日期是这样的20,21,22.我该怎么做?
我很确定这已经回答了十几亿次,但无论如何:
$start = strtotime('20-04-2010 10:00');
$end   = strtotime('22-04-2010 10:00');
for($current = $start; $current <= $end; $current += 86400) {
    echo date('d-m-Y',$current);
}

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

通过给出天数:

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

用PHP5.3

$period = new DatePeriod(
    new DateTime('20-04-2010'),DateInterval::createFromDateString('+1 day'),new DateTime('23-04-2010') // or pass in just the no of days: 2
);

foreach ( $period as $dt ) {
  echo $dt->format( 'd-m-Y' );
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读