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

前端 未结 4 1705
自闭症患者
自闭症患者 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:54

    If you are creating an invoicing system, you have to think about the bank holidays, Easter, etc. It is not simple to compute it.

    The best solution I have ever seen is to pregenerate a table with days and its type to SQL database (row per day = 365 rows per year) and then perform simple count query with proper selection (WHERE clause).

    You can find this solution fully described in Joe Celko's Thinking in Sets: Auxiliary, Temporal, and Virtual Tables in SQL

提交回复
热议问题