RE: [PHP] Last working day of a month



-----Original Message-----
From: Andrew Ballard [mailto:aballard@xxxxxxxxx]
Sent: Thursday, December 04, 2008 8:32 AM
To: Angelo Zanetti
Cc: php-general@xxxxxxxxxxxxx
Subject: Re: [PHP] Last working day of a month
Importance: Low

On Thu, Dec 4, 2008 at 9:03 AM, Angelo Zanetti <angelo@xxxxxxxxxxxxxxx>
wrote:
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?


If your application is already using a database, I would use a date
table rather than a holiday table. You can add columns to indicate
whether each date is a workday, weekday, weekend, holiday, or any
other date category/group that you need to track.

That seems like a waste of space and database calls to me. (Yes, I know space is cheap... but it should at least be thought about briefly. Using that space costs cycles, etc.) Since the exceptions to his rule are so few in comparison to the days that follow, I think documenting the exceptions and assuming it's a workday if it's not an exception makes more sense (IMHO).

I'd probably store all holidays in a table and assume that Saturdays/Sundays are not workdays unless they have a corresponding entry in the same table that holds the holidays. Call the table "exceptions." The exception to a workday is a holiday. The exception to a weekend is a workday. :)

HTH,


// Todd


Relevant Pages

  • Re: [PHP] Suggestions?
    ... You can't do a simple count of the holidays and add that, because you might end up with yet another holiday in the result. ... You find 1 holiday in between, so you add 7 business days and end up on New Year's Day, a non-business day. ... I think MySQL has built-in holiday / work day calculations, ... Application and Templating Framework for PHP ...
    (php.general)
  • Re: The difference of "I havent been/wasnt busy today."
    ... |I haven't been busy today. ... |I have spoken to the boss today about my holiday. ... "I spoke to the boss about my holiday." ...
    (alt.usage.english)
  • Re: The difference of "I havent been/wasnt busy today."
    ... |I haven't been busy today. ... |I spoke to the boss today about my holiday. ... |I have spoken to the boss today about my holiday. ...
    (alt.usage.english)
  • Re: The difference of "I havent been/wasnt busy today."
    ... I haven't been busy today. ... I spoke to the boss today about my holiday. ... I have spoken to the boss today about my holiday. ...
    (alt.usage.english)
  • Re: by-the-way
    ... But it's true - I get fed up being 'on holiday' after a month or two. ... I've been a bit busy trying to get outlets for the jewelry and get it ... B**dy cheek - is he allowed to do that? ...
    (soc.culture.scottish)