simple question

simple question

am 25.11.2005 15:07:50 von How Loon

Greetings,

How to we know how many Tuesday within a predefined
time frames, say

Number of Monday between 1 Jan 2005 until 31 Aug 2005
OR
How many Saturday between 13 Feb 2005 until 17 May
2005

Thanks.




__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32@m.gmane.org

Re: simple question

am 25.11.2005 16:03:36 von Felix Geerinckx

On 25/11/2005, ascll wrote:

> How to we know how many Tuesday within a predefined
> time frames, say
>
> Number of Monday between 1 Jan 2005 until 31 Aug 2005
> OR
> How many Saturday between 13 Feb 2005 until 17 May 2005

Create a calendar table:

CREATE TABLE calendar (
dt DATE NOT NULL PRIMARY KEY, -- date
yr MEDIUMINT UNSIGNED NOT NULL, -- year
mo TINYINT UNSIGNED NOT NULL, -- month
dom TINYINT UNSIGNED NOT NULL, -- day of month
doy MEDIUMINT UNSIGNED NOT NULL, -- day of year
dow TINYINT UNSIGNED NOT NULL -- day of week
);

and fill it (with a big enough period).

Then:

SELECT
COUNT(*)
FROM calendar
WHERE
dt BETWEEN '2005-02-13' AND '2005-05-17'
AND dow = 7 -- 7 = saturday
;

--
felix

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32@m.gmane.org

Re: simple question

am 25.11.2005 16:23:45 von Daniel da Veiga

If I got what you want right, it would be a LOT easier to use the
programming language of your choice to get this kinda results, most
languages provide specific time and date functions that would get what
you want. The only way to do that with a DB would be to populate a
table with a date field and a lot of records (one for each day of the
period?) in order to select and count the result of a query like:

select count(*) from table_of_days where
function_that_gets_the_day_of_the_week(field) =3D "Tuesday"; (I don't
remember if the function returns the name or the index of the day in
the week)

I don't remeber the exact name of the function, but I'm pretty sure
there's one, take a look at the manual.

On 11/25/05, ascll wrote:
> Greetings,
>
> How to we know how many Tuesday within a predefined
> time frames, say
>
> Number of Monday between 1 Jan 2005 until 31 Aug 2005
> OR
> How many Saturday between 13 Feb 2005 until 17 May
> 2005
>
> Thanks.
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>
> --
> MySQL Windows Mailing List
> For list archives: http://lists.mysql.com/win32
> To unsubscribe: http://lists.mysql.com/win32?unsub=3Ddanieldaveiga@gma=
il.com
>
>


--
Daniel da Veiga
Computer Operator - RS - Brazil
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/IT/P/O d-? s:- a? C++$ UBLA++ P+ L++ E--- W+++$ N o+ K- w O M- V-
PS PE Y PGP- t+ 5 X+++ R+* tv b+ DI+++ D+ G+ e h+ r+ y++
------END GEEK CODE BLOCK------

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=3Dgcdmw-win32@m.gmane.org