我想在日期范围之间找到一天的日期。
E.g。 date1 = 04/12/2012(星期四)和date2 = 04/30/2012。
因此PHP函数应该返回两个日期:
19/12/2012(开始日期后的第1个星期四)和2012年12月26日(第2个星期四) 开始日期之后)。
对于大日期范围功能应返回第1,第2,第3,第4 ......所以在发生日期。
答案 0 :(得分:3)
评论中列出的副本(Getting all dates for Mondays and Tuesdays for the next year)有一个相当详细的答案。以下是使用strtotime
与Relative Formats:
// Initialize our dates to UNIX timestamps
$startDate = strtotime( 'next Tuesday', strtotime($startDate) );
$endDate= strtotime($endDate);
// Output all Tuesdays prior to our end date
while ($startDate < $endDate) {
echo date('n/j/Y', $startDate ). "\n";
// Get next Tuesday relative to last Tuesday
$startDate = strtotime( 'next Tuesday', $startDate );
}
使用今天($startDate
)和今天2个月($endDate
)作为示例,上述输出:
4/17/2012
4/24/2012
5/1/2012
5/8/2012
5/15/2012
5/22/2012
5/29/2012
6/5/2012
注意:确保您使用proper date format来获得准确的结果。