Re: [PHP] Last working day of a month
On Thu, Dec 4, 2008 at 9:03 AM, Angelo Zanetti [EMAIL PROTECTED] 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? Any advice is appreciated. TIA Angelo 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. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Last working day of a month
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? Any advice is appreciated. TIA Angelo Web: http://www.elemental.co.za -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Last working day of a month
-Original Message- From: Andrew Ballard [mailto:[EMAIL PROTECTED] Sent: Thursday, December 04, 2008 8:32 AM To: Angelo Zanetti Cc: php-general@lists.php.net Subject: Re: [PHP] Last working day of a month Importance: Low On Thu, Dec 4, 2008 at 9:03 AM, Angelo Zanetti [EMAIL PROTECTED] 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
Re: [PHP] Last working day of a month
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Last working day of a month
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 Well it should!! The advice I love most of all is like this, helping me see the clear logic, and then letting me figure out how to write it w/the language at hand. This reply post of mine does not add anything for anyone; sometimes I just can't help express my appreciation for things. Brilliant Jochem! -G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php