The dating code
Rather than using mktime() and a loop, James can subtract the current timestamp from the timestamp of the date in question and divide that by the number of seconds in a day: Another usage could find itself in a class submitted by Kyle M Hall which aids in the creation of timestamps from the recent past for use with My SQL.
Rather than the looping and fine tuning of a date, Kyle can use the raw UNIX timestamps (this is untested code): In order to define leap year you must considre not only that year can be divide by 4!
I couldn't find a simple way to do that in PHP, so I threw this together.
It replicates the functionality of Open Office's NETWORKDAYS function - you give it a start date, an end date, and an array of any holidays you want skipped, and it'll tell you the number of business days (inclusive of the start and end days! I've tested it pretty strenuously but date arithmetic is complicated and there's always the possibility I missed something, so please feel free to check my math.
One of the most useful skills you can utilize when performing date math is taking full advantage of the UNIX timestamp.
The UNIX timestamp was built for this kind of work.
Consider I've been flicking through the comments looking for some succinct date code and have noticed an alarming number of questions and over-burdened examples related to date mathematics.However, before PHP 5.1.0 this range was limited from to on some systems (e.g. You can prevent a recognized character in the format string from being expanded by escaping it with a preceding backslash.If the character with a backslash is already a special sequence, you may need to also escape the backslash. Note that you should escape any other characters, as any which currently have a special meaning will produce undesirable results, and other characters may be assigned meaning in future PHP versions.Note that some formatting options are different from My SQL.
For example using a 24 hour notation without leading zeros is the option '%G' in PHP but '%k' in My SQL."skip July 4th in any year, skip the first Monday in September in any year"). If you see the number 86400 in a date calculation, think very hard before deciding that it is correct. In many places, some days have only 82,800 seconds and some have 90,000. Assuming that now plus 86,400 seconds is equivalent to some time tomorrow can sometimes be wrong.