calculating the total instances in a month...

# Thread: calculating the total instances in a month...

1. Senior Member
Join Date
Dec 1969
Posts
175

## calculating the total instances in a month...

I have a range of dates in a column like..<BR>10/26/2002, 10/28/2002, 11/4/2002, 11/15/2002, 11/22/2002, 12/1/2002...<BR><BR>How do I calculate how many dates are there in each month from the table... here the answer for the above would be<BR>October = 2<BR>November = 3<BR>December = 1...<BR><BR>Thanx

2. Senior Member
Join Date
Dec 1969
Posts
2,437

## Which DBMS? <EOP>

select count(*),monthName<BR> from (select extract(month from dateColumn)as monthName<BR> from t) s<BR> group by monthName<BR><BR>What about different years?

3. Senior Member
Join Date
Dec 1969
Posts
175

## SQL Server, actually you..

.. are right. It should also be year sensitive.<BR><BR>Basically I have column of months displayed on the top (coming from the database). Below each month I need to display, how many times this class is being taken. The user selects from the calendar all the dates that is being required... and that value goes an resides in the database as a String Like "10/21/2002, 10/24/2002, 11/3/2002, 12/23/2002, 12/24/2002, 01/12/2003"...<BR><BR>So the result shd be<BR>October 2002 &#124 November 2002 &#124 December 2002 &#124 January 2003<BR>2 &#124 1 &#124 2 &#124 1<BR><BR>Thanx

4. Senior Member
Join Date
Dec 1969
Posts
2,437

## RE: SQL Server, actually you..

The other example was using ANSI sql. The extract function is not supported by T-sql so you could write it as <BR><BR>select count(*),year(dateColumn),month(dateColumn) <BR> from t<BR> group by year(dateColumn),month(dateColumn) <BR>order by year(dateColumn),month(dateColumn) <BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•