> Hi,
> 
> Is it possible to get the number of saturdays and sundays for a given
> month
> / year?
> 
> Thanks for your help.

Hi Shaun,

Not sure if there's a graceful PHP solution (there probably is, but can't
think of one, myself, right at this moment) but it sounds like what you
might need is a calendar table in your database.

This is a common approach to solving a number of date-related issues, of the
type you're asking about.

A typical structure might be

Recid (int autoincrement)
Date (datetime)
Year (int)
Month (int)
Day (int)
Day_name (varchar)
Month_name (varchar)
Etc..

A record for today's date would then look like:

1, '2005-09-01', 2005, 9, 1, 'Thursday', 'September'

There are a number of other fields you could add, depending on your needs
(financial_quarter, for example, if your site is a business application,
week_num and so on)

You would then write a routine that would populate the table with
appropriate values for any given time period (10 years into the future, for
example) and thus would be able to very simply perform operations like:

SELECT COUNT(*) FROM date_info WHERE year=2005 and month=9 and
(day_name='Saturday' or day_name='Sunday')

Again, there may be a better solution in PHP, but any date-intensive
application would probably benefit from the above approach. In particular,
it becomes very useful when you use the recid value for the date from your
calendar table in application data tables instead of the actual date,
allowing you to perform very flexible queries where you might be interested
in sales results for all the Thursdays in every September for the last 5
years, etc.

Regards,

Murray
---
"Lost in thought..."
http://www.planetthoughtful.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to