I want to calculate the number of weekdays days in a give month and year. Weekdays means monday to friday. How do i do it ?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
This is the simplest code I could come up with. You really would need to create an array or a database table to hold the holidays to get a true, "Working Days" count, but that wasn't what was asked, so here you go, hope this helps someone.
Some basic code:
Remove the
@
if your PHP error warning doesn't show notices.The functions calculate the number of weekdays using:
try this one
Calculate working days in a month from any date:
I've come up with a non-loop function. Much better in terms of performance. It might seem messy but it just needs to ask PHP the first day's weekday and the month's number days: the rest are arithmetical operations based on logic.