[英]php time periods without weekends
Given the date of a day and a number (X) of days I'd need to retrieve the date after X days without considering Saturdays or Sundays. 鉴于一天的日期和数天(X)我需要在X天后检索日期而不考虑星期六或星期日。
For example: 例如:
date1= Y-m-d -where-> Monday of the week #20
date1+2 days= Wednesday of the week #20
date2= Friday of the week #22
date2+1 day= Monday of week #23
Is there some built-in function for helping with that task? 是否有一些内置函数可以帮助完成这项任务? or must I implement it? 或者我必须实施它吗?
Thanks 谢谢
This seems to work ( demo ): 这似乎工作( 演示 ):
$date = strtotime('2012-06-01'); // Friday
echo date('Y-m-d (l)', strtotime('+1 weekdays', $date)); // 2012-06-04 (Monday)
echo date('Y-m-d (l)', strtotime('+6 weekdays', $date)); // 2012-06-11 (Monday)
echo date('Y-m-d (l)', strtotime('+8 weekdays', $date)); // 2012-06-13 (Wednesday)
echo date('Y-m-d (l)', strtotime('+9 weekdays', $date)); // 2012-06-14 (Thursday)
echo date('Y-m-d (l)', strtotime('+10 weekdays', $date)); // 2012-06-17 (Sunday)
Sorry, but I don't know what's wrong with the last one; 对不起,但我不知道最后一个有什么问题; perhaps someone else can shed some light into it. 也许其他人可以对此有所了解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.