Given two dates what is the best way of finding the number of weekdays in PHP?

前端 未结 4 1669
自闭症患者
自闭症患者 2021-01-24 08:53

The title is pretty much self explanatory. Given two dates what is the best way of finding the number of week days using PHP? Week days being Monday to Friday.

For insta

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-24 09:57

    One way would be to convert the dates to unix timestamps using strtotime(...), subtracting the results and div'ing with 86400 (24*60*60):

    $dif_in_seconds = abs(strtotime($a) - strtotime($b));
    $daysbetween = $dif_in_seconds / 86400;
    

    ETA: Oh.. You meant weekdays as in Mon-Fri.. Didn't see that at first..

提交回复
热议问题