我相信如果有可能的话我跟你联系。
我有 2个包含日期的字符串:d/m/Y
要即时:
$from_date="17/10/2018";
$till_date ="20/10/2018";
是否可以打印这些日期之间的总天数,以及打印日期?
要即时:
4 天
17/10/2018
18/10/2018
19/10/2018
20/10/2018
使用 DateTime
类和它的关联方法 createFromFormat
将提供的日期转换为可以行的格式并添加 DateInterval
使它的相当的straigtforward 。
$start = DateTime::createFromFormat('d/m/Y','17/10/2018');
$end = DateTime::createFromFormat('d/m/Y','20/10/2018');
$int = new DateInterval('P1D'); #1 day
while( $start <= $end )echo $start->add( $int )->format('Y-m-d'). '<br/>';
输出:
2018-10-18
2018-10-19
2018-10-20
2018-10-21
是的,你可以尝试这样做:
$arr = array("17-10-2018","18-10-2018","19-10-2018","20-10-2018");
$countDateBetweenDates = 0;
foreach ($arr as $value) {
if (strtotime($value)> strtotime("17-10-2018") && strtotime($value) <strtotime("20-10-2018")) {
$countDateBetweenDates = $countDateBetweenDates + 1;
}
}
echo $countDateBetweenDates;