PHP 中的工作日(周一至周五)
有没有办法使用 strtotime
将工作日(周一至周五)添加到日期?或者其他方法?我想做的是:
date ( 'Y-m-j' , strtotime ( '+3 working days' ) )
Is there a way to use strtotime
to add working days (Monday to Friday) to a date? Or some other method? What I want to do is:
date ( 'Y-m-j' , strtotime ( '+3 working days' ) )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您限制为工作日,请使用字符串 weekdays。
这将使您提前 3 个工作日,因此如果是星期四,则会增加额外的周末时间。
来源: http://www.php.net/manual/en/datetime .formats.relative.php
If you are limiting to weekdays use the string weekdays.
This should jump you ahead by 3 weekdays, so if it is Thursday it will add the additional weekend time.
Source: http://www.php.net/manual/en/datetime.formats.relative.php
您也可以这样做:
请参阅:
https://www.php。 net/manual/en/function.date-create.php
https ://www.php.net/manual/en/datetime.modify.php
You can do this too:
See:
https://www.php.net/manual/en/function.date-create.php
https://www.php.net/manual/en/datetime.modify.php
当我需要大量工作日时,我发现了这款越野车。我正在查找当月 1 日之后的 X 个工作日。
起初看起来很棒,直到添加>之后5 个工作日(与@zerkms 发现的类似)。
事实证明这对我来说更准确。
I have found this buggy when needing a larger amount of weekdays. I was looking for X amount of business days after the 1st of the current month.
Looked great at first until after adding > 5 business days (similar to what @zerkms found).
This has proved more accurate for me.
对于 PHP >= 5.6
For PHP >= 5.6
我认为可以很容易地开发一个功能,您可以只导出一周中的当前日期,并且可以添加两个,并且 5 的 mod 将轻松为您提供工作日。
您可以使用数组导出工作日名称,也可以使用此方法。
I think a function can be easily developed that you can just export current day no of the week and you can add two and mod of 5 will give you easily weekday.
And you can export the weekday name by using an array, this method can alternatively be used.
我递归地做,为我工作
I do it recursively, worked for me
对于旧版本的 PHP < 5.3
For older versions of PHP < 5.3