指定持续时间的php日期列表

发布于 2024-08-26 16:39:30 字数 204 浏览 1 评论 0原文

是否有任何 php 类或函数可以为我们提供特定持续时间的所有天数?例如,如果我想要一个从25/03/2010(2010年3月25日)到15/05/2010(2010年5月15日)的日期列表,它会给我:

25/03/2010 26/03/2010 26/03/2010 .... .... .... 14/05/2010 15/05/2010

非常感谢您的帮助!

is there any php classes or functions, which will gives us all the days from specific duration? for example, if i want a list of dates from 25/03/2010 (25th march 2010) to 15/05/2010 (15th May 2010), it will give me:

25/03/2010
26/03/2010
26/03/2010
....
....
....
14/05/2010
15/05/2010

thanks a lot for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请别遗忘我 2024-09-02 16:39:30

在 php5.3 中,使用新的 DatePeriod< /a> 对象:

$begin = new DateTime( '2010-03-25' );
$end = new DateTime( '2010-05-15 23:59:59' );

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

foreach ( $period as $dt )
  echo $dt->format( "Y-m-d\n " );

It's easy in php5.3 with the new DatePeriod objects:

$begin = new DateTime( '2010-03-25' );
$end = new DateTime( '2010-05-15 23:59:59' );

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

foreach ( $period as $dt )
  echo $dt->format( "Y-m-d\n " );
我偏爱纯白色 2024-09-02 16:39:30
$day1 = strtotime ('25/03/2010');
$day2 = strtotime ('15/05/2010');

$oneday = 60 * 60 * 24;

for ($day = $day1; $day <= $day2; $day + $oneday)
{
    echo date ('Y-m-d', $day);
}

应该做。

$day1 = strtotime ('25/03/2010');
$day2 = strtotime ('15/05/2010');

$oneday = 60 * 60 * 24;

for ($day = $day1; $day <= $day2; $day + $oneday)
{
    echo date ('Y-m-d', $day);
}

Should do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文