If I want to default a date to the next working day I am using the following:
<?php
echo(date('d/m/Y',strtotime('+1 Weekdays')));
?>
For example: If a user is adding an item on a Friday it is given a default of the following Monday - the next working day.
I have to create a schedule of events with a start and end date. The end date needs to 1 year in the future on the preceding working day.
For example: If a user adds a schedule that has a start day of Wednesday and the same date in a years time happens to be a Sunday, then the end date needs to default to the previous Friday - the preceding working day.
2条答案
按热度按时间x8diyxa71#
我找到了答案:
qpgpyjmq2#
您只需要在今天的日期上加上一年,然后检查星期几,如果是“星期六”或“星期日”,则减去一个工作日。The PHP
DateTime
object通过format()
和modify()
方法使这一操作变得简单。在所有这些情况下:
上面将输出: