Re: Last working day of a month
| From: | Jochem Maas | Date: | Thu, 04 Dec 2008 15:15:05 +0000 |
| Subject: | Re: Last working day of a month | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-284097@lists.php.net to get a copy of this message | ||
Angelo Zanetti schreef:
> Hi all,
>
> I am busy trying to figure out how to get the last working day in a month.
>
> I was wondering if there was a script already written, but this is what I
> imagine should work:
>
> Get the current day and see if it's the last day of the month. If its true
> check if it's a Saturday or Sunday if it's either of those 2 days then
> return false else return true?
>
> I also need to take public holidays into account. What would be the best
> solution for that? Store the public holidays in a table and check if the
> current day isn't a public holiday?
you need a process with a few simple steps.
1. find the last day of the month, this is quite easy ... google gives answers
as does the manual. e.g.:
http://lutrov.com/blog/php-last-day-of-the-month-calculation/
2. determine if this is a week day. if yes go to step three else 'roll the date back'
24 hours and go to step 2.
3. determine if this is a holiday, if yes 'roll the date back' 24 hours and go
to step 2. else you have found the last working day of the month.
with regard to determining if a day is a holiday your best bet is to store these
in a database table. and check against that ... you may be able to find a source
of holiday data online from which you can sync your local datasource periodically
(e.g. via a cron job).
hth
>
> Any advice is appreciated.
>
> TIA
> Angelo
>
>
> Web: http://www.elemental.co.za
>
>
>