Re: date functions
| From: | Miguel Cruz | Date: | Sun, 19 May 2002 05:07:21 +0000 |
| Subject: | Re: date functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-98328@lists.php.net to get a copy of this message | ||
On Sun, 19 May 2002, Josh Edwards wrote:
> Does anyone know a good way to count the days between two dates. ie how
> many Mondays fall between two dates. As a starting point I have calculated
> the start and end dates and the no of days b/w them.
Pretty much common sense, right? How about something like this:
// $timestamp1 = starting date (unix timestamp)
// $timestamp2 = ending date (unix timestamp)
// $weekday = day we're counting (0 = Sunday, 1 = Monday, etc.)
function weekdaysBetween ($timestamp1, $timestamp2, $weekday)
{
return floor(intval(($timestamp2 - $timestamp1) / 86400) / 7)
+ ((date('w', $timestamp1) <= $weekday) ? 1 : 0);
}
miguel