如何获得$ date + 5以排除周末? [英] How to get $date + 5 to exclude weekends?

查看:34
本文介绍了如何获得$ date + 5以排除周末?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些页面需要在将来设置日期(由变量设置的2天或5天).该日期只需要计算星期一-星期五,不包括周末.

I have some pages that require a date to be set in the future (either 2 or 5 days as set by a variable). This date needs to be only counting Monday - Friday, excluding weekends.

到目前为止,我所拥有的($ tts是2或5的变量,具体取决于页面);

What I have so far ($tts is the variable of 2 or 5 depending on page);

$Today = date('N:m:y');
$NewDate = date('l \t\h\e jS \o\f F',strtotime($Today) + (24*3600*$tts));
$businessDays = [1, 2, 3, 4, 5]; 
echo $NewDate;

这在不排除周末的情况下有效.我尝试使用$ businessDays,但不确定如何使用它来计算$ Today和$ NewDate之间的日期.

This works without excluding weekend days. I have tried to use the $businessDays but I'm unsure of how I can use this to count what days are between $Today and $NewDate

推荐答案

尝试:

$plusFive = strtotime( '+5 weekday' );
$plusFive = date( 'Y-m-d', $plusFive );

strtotime还带有第二个参数,可以作为+5的基数.

strtotime also takes a second parameter which could be the base for the +5.

这篇关于如何获得$ date + 5以排除周末?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆