PC Review


Reply
Thread Tools Rate Thread

Count # of Days in a Month

 
 
DF
Guest
Posts: n/a
 
      4th May 2007
Does someone know off hand a function that would count the number of
individual days in a given month? For example, how many Mondays in
May 2007, how many Tuesdays, etc... I've searched the help files and
did not find anything I could use. Thanks in advance for your help.

--DFruge

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZSBI?=
Guest
Posts: n/a
 
      4th May 2007
Chip Pearson has the answer

http://www.cpearson.com/excel/holidays.htm

Mike

"DF" wrote:

> Does someone know off hand a function that would count the number of
> individual days in a given month? For example, how many Mondays in
> May 2007, how many Tuesdays, etc... I've searched the help files and
> did not find anything I could use. Thanks in advance for your help.
>
> --DFruge
>
>

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      4th May 2007
in VBA (demo'd from the immediate window)

? Day(DateSerial(2007,05+1,0))
31

in excel

=Day(Date(2007,05+1,0))


--
Regards,
Tom Ogilvy



"DF" wrote:

> Does someone know off hand a function that would count the number of
> individual days in a given month? For example, how many Mondays in
> May 2007, how many Tuesdays, etc... I've searched the help files and
> did not find anything I could use. Thanks in advance for your help.
>
> --DFruge
>
>

 
Reply With Quote
 
merjet
Guest
Posts: n/a
 
      4th May 2007
http://groups.google.com/group/micro...4cf65dfbed8dea

Hth,
Merjet


 
Reply With Quote
 
merjet
Guest
Posts: n/a
 
      4th May 2007
http://groups.google.com/group/micro...4cf65dfbed8dea

Hth,
Merjet


 
Reply With Quote
 
=?Utf-8?B?Um9uIENvZGVycmU=?=
Guest
Posts: n/a
 
      4th May 2007
With
A1: (any date)
B1: (a number from 1-7, inclusive)......1:Sun, 2:Mon.....7:Sat

This formula returns the count of the referenced day that are in the month
containing the date in A1

C1:
=SUM(INT(((WEEKDAY(DATE(YEAR(A1),MONTH(A1),1)-B1)+(DAY(DATE(YEAR(A1),MONTH(A1)+1,0))-1))/7)))

or....alternatively
C1:
=SUMPRODUCT(--(WEEKDAY(ROW(INDEX(A:A,DATE(YEAR(A1),MONTH(A1),1)):INDEX(A:A,DATE(YEAR(A1),MONTH(A1)+1,0))))=B1))

If
A1 contains 5/15/2007
B1 contains 3 (Tue)
then the formula returns 5 (there are 5 Tuesdays in May 2007)

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


"DF" wrote:

> Does someone know off hand a function that would count the number of
> individual days in a given month? For example, how many Mondays in
> May 2007, how many Tuesdays, etc... I've searched the help files and
> did not find anything I could use. Thanks in advance for your help.
>
> --DFruge
>
>

 
Reply With Quote
 
okrob
Guest
Posts: n/a
 
      4th May 2007
On May 4, 1:12 pm, DF <dfr...@gmail.com> wrote:
> Does someone know off hand a function that would count the number of
> individual days in a given month? For example, how many Mondays in
> May 2007, how many Tuesdays, etc... I've searched the help files and
> did not find anything I could use. Thanks in advance for your help.
>
> --DFruge


And another way to do it is the following formulas for each of the
days...

Mondays =4+(DAY("5-1-2007"-DAY("5-1-2007")+CHOOSE(WEEKDAY("5-1-2007"-
DAY("5-1-2007")),1,7,6,5,4,3,2)+28)>28)

Tuesdays =4+(DAY("5-1-2007"-DAY("5-1-2007")+CHOOSE(WEEKDAY("5-1-2007"-
DAY("5-1-2007")),2,1,7,6,5,4,3)+28)>28)

Wednesdays =4+(DAY("5-1-2007"-DAY("5-1-2007")
+CHOOSE(WEEKDAY("5-1-2007"-DAY("5-1-2007")),3,2,1,7,6,5,4)+28)>28)

Thursdays =4+(DAY("5-1-2007"-DAY("5-1-2007")+CHOOSE(WEEKDAY("5-1-2007"-
DAY("5-1-2007")),4,3,2,1,7,6,5)+28)>28)

Fridays =4+(DAY("5-1-2007"-DAY("5-1-2007")+CHOOSE(WEEKDAY("5-1-2007"-
DAY("5-1-2007")),5,4,3,2,1,7,6)+28)>28)

Saturdays =4+(DAY("5-1-2007"-DAY("5-1-2007")+CHOOSE(WEEKDAY("5-1-2007"-
DAY("5-1-2007")),6,5,4,3,2,1,7)+28)>28)

Sundays =4+(DAY("5-1-2007"-DAY("5-1-2007")+CHOOSE(WEEKDAY("5-1-2007"-
DAY("5-1-2007")),7,6,5,4,3,2,1)+28)>28)

 
Reply With Quote
 
Dave Miller
Guest
Posts: n/a
 
      4th May 2007
DFruge,

This will work for you:

Regards,
David Miller

Function HowManyMondaysInMay2007()
Debug.Print GetDaysInMonth("Monday", "05/01/07")
End Function

Function GetDaysInMonth(sDay As String, dtm As Date) As Long
Dim DaysInMonth As Long, _
i As Integer

DaysInMonth = Day(DateSerial(Year(dtm), Month(dtm) + 1, 0))

For i = 1 To DaysInMonth
If WeekdayName(Weekday(dtm + i)) = sDay Then
GetDaysInMonth = GetDaysInMonth + 1
End If
Next
End Function

 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      4th May 2007
On 4 May 2007 11:12:35 -0700, DF <(E-Mail Removed)> wrote:

>Does someone know off hand a function that would count the number of
>individual days in a given month? For example, how many Mondays in
>May 2007, how many Tuesdays, etc... I've searched the help files and
>did not find anything I could use. Thanks in advance for your help.
>
>--DFruge



=4+(DAY(A1-DAY(A1)+1-WEEKDAY(A1-DAY(A1+DOW))+35)>7)

Where DOW is the Day Of the Week with
Monday = 1
Tuesday = 2
etc.

Or, in VBA, something like:

========================================
Option Explicit
Sub WDinMonth()
Dim DOW As Long
Dim Dt As Date

Dt = DateValue(InputBox("Enter Month and Year"))
Debug.Print "Number of Weekdays in " & Format(Dt, "mmm yyyy")

For DOW = 1 To 7
Debug.Print _
Application.WorksheetFunction.Choose(DOW, _
"Monday", "Tuesday", "Wednesday", "Thursday", _
"Friday", "Saturday", "Sunday"), _
5 + (Day(Dt - Day(Dt) + 1 - Weekday(Dt - Day(Dt + DOW)) + 35) < 7)
Next DOW

End Sub
====================================

Note that in VBA the comparison in the formula is reversed because, in VBA,
TRUE = -1 and FALSE = 0


--ron
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: CountDays? need to count days in range by month Bob Phillips Microsoft Excel Worksheet Functions 0 11th Jan 2007 12:50 AM
Re: CountDays? need to count days in range by month Dave Peterson Microsoft Excel Worksheet Functions 0 11th Jan 2007 12:47 AM
Count days of a certain month between date fields =?Utf-8?B?ZWlsZWVuamVzcw==?= Microsoft Access Queries 4 21st Jun 2006 05:34 PM
Count work days in a month =?Utf-8?B?RVByYXR0?= Microsoft Access Queries 1 17th Nov 2005 04:50 PM
Count number of days in given month? =?Utf-8?B?QnJ5YW4=?= Microsoft Excel Worksheet Functions 10 2nd Feb 2005 11:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:13 AM.