note 40191 deleted from function.date by irchtml
| From: | irchtml@php.net | Date: | Tue, 24 Feb 2004 23:23:09 +0000 |
| Subject: | note 40191 deleted from function.date by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65674@lists.php.net to get a copy of this message | ||
Note Submitter: mcrackan
----
I finally figured out the solution to 'find X number of weekdays starting from day Y'. My
version calculates in seconds (unixtime) but if you need to use whole days, it shouldn't be
hard to tweak. Here's the verbose version:
// numeric day of week
$numdow = date("w", $startunix);
// numeric days left in week 1
$wk1dayslft = 5 - $numdow;
// days later after wk 1
$leftafterwk1 = $daysltr - $wk1dayslft;
// full weeks left
$fullwkslft = floor($leftafterwk1 / 5);
// extra days left for final week
$xdayslft = $leftafterwk1 % 5;
// calender days left (week 1 days + (weeks x 7) + final week days)
$caldayslft = $wk1dayslft + ($fullwkslft * 7) + $xdayslft;
// seconds left
$secslft = $spd * $caldayslft;
// end time
$endunix = $startunix + $secslft;