Hi there,
Does anyone know a function on how to genetate the number in a given month
and year.
E.g. Month=March, Year=2005. Week count = 5
Month=February, Year=2005. Week count = 4

Re: Week Count for Month by McKirahan

McKirahan
Mon Feb 21 10:07:41 CST 2005

"Kevin Humphreys" <khumphreys@hotmail.com> wrote in message
news:uYyOViCGFHA.1456@TK2MSFTNGP09.phx.gbl...
> Hi there,
> Does anyone know a function on how to genetate the number in a given month
> and year.
> E.g. Month=March, Year=2005. Week count = 5
> Month=February, Year=2005. Week count = 4

What is your criteria for a "week"?

If you sum up the weeks in each month will it equal 52? 53? or what?



Re: Week Count for Month by Matthias

Matthias
Mon Feb 21 14:58:25 CST 2005

McKirahan wrote:
> "Kevin Humphreys" <khumphreys@hotmail.com> wrote in message
> news:uYyOViCGFHA.1456@TK2MSFTNGP09.phx.gbl...
>
>>Hi there,
>>Does anyone know a function on how to genetate the number in a given month
>>and year.
>>E.g. Month=March, Year=2005. Week count = 5
>>Month=February, Year=2005. Week count = 4
>
>
> What is your criteria for a "week"?
>
> If you sum up the weeks in each month will it equal 52? 53? or what?
>

Hi McKirahan,
I've never seen a month with count of weeks ;-)

I assume he's after the number of weeks a month spreads over aka
rows in 7 columns calendars. This script should be locale independent.
Either the system setting has to match the desired FirstWeekDay/
FirstWeekinYear or you set them explicitly.

' WeeksInMonth -----------------------------------------------------

FirstWeekDay=0
' 0 vbUseSystemDayOfWeek
' 1 vbSunday
' 2 vbMonday
' 3 vbTuesday
' 4 vbWednesday
' 5 vbThursday
' 6 vbFriday
' 7 vbSaturday

FirstWeekInYear=0
' 0 vbUseSystem
' 1 vbFirstJan1
' 2 vbFirstFourDays
' 3 vbFirstFullWeek

MyDate=Date

if wscript.Arguments.Count then _
if IsDate(wscript.Arguments(0)) then _
MyDate=wscript.Arguments(0)

wscript.echo MonthName(Month(MyDate)) & " " & Year(MyDate) & " has "_
& WeeksInMonth(MyDate) & " weeks"

Function WeeksInMonth(MyDate)
if Isdate(MyDate) then
FirstDayofMonth=DateAdd("d",1-day(MyDate),MyDate)
LastDayofMonth=DateAdd("m",1,FirstDayofMonth)
LastDayofMonth=DateAdd("d",-1,LastDayofMonth)
WeeksInMonth=1+DateDiff("ww", FirstDayofMonth, LastDayofMonth, _
FirstWeekDay, FirstWeekInYear)
end if
End Function

' WeeksInMonth -----------------------------------------------------

HTH

--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+

Re: Week Count for Month by McKirahan

McKirahan
Mon Feb 21 15:32:43 CST 2005

"Matthias Tacke" <Matthias@Tacke.de> wrote in message
news:cvdi1f$6mv$04$1@news.t-online.com...
> McKirahan wrote:
> > "Kevin Humphreys" <khumphreys@hotmail.com> wrote in message
> > news:uYyOViCGFHA.1456@TK2MSFTNGP09.phx.gbl...
> >
> >>Hi there,
> >>Does anyone know a function on how to genetate the number in a given
month
> >>and year.
> >>E.g. Month=March, Year=2005. Week count = 5
> >>Month=February, Year=2005. Week count = 4
> >
> >
> > What is your criteria for a "week"?
> >
> > If you sum up the weeks in each month will it equal 52? 53? or what?
> >
>
> Hi McKirahan,
> I've never seen a month with count of weeks ;-)
>
> I assume he's after the number of weeks a month spreads over aka
> rows in 7 columns calendars.

I won't assume; I'll wait for the OP's response.



Re: Week Count for Month by Dr

Dr
Mon Feb 21 17:38:25 CST 2005

JRS: In article <uYyOViCGFHA.1456@TK2MSFTNGP09.phx.gbl>, dated Mon, 21
Feb 2005 15:18:20, seen in news:microsoft.public.scripting.vbscript,
Kevin Humphreys <khumphreys@hotmail.com> posted :

>Does anyone know a function on how to genetate the number in a given month
>and year.
>E.g. Month=March, Year=2005. Week count = 5
>Month=February, Year=2005. Week count = 4

Yes. But first you have to define what you mean by a week, and which
weeks are associated with any given month. Two examples are inadequate
to determine the algorithm

Outside the USA, it would be considered reasonable to use ISO 8601
weeks, and to assign to months analogously to years.

Then the answer is easily determined from the day-of-month of the zeroth
Thursday of the following month - add 6, then div 7. That's more
efficient than counting Thursdays, obviously.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Re: Week Count for Month by Dr

Dr
Tue Feb 22 11:40:49 CST 2005

JRS: In article <cvdi1f$6mv$04$1@news.t-online.com>, dated Mon, 21 Feb
2005 21:58:25, seen in news:microsoft.public.scripting.vbscript,
Matthias Tacke <Matthias@Tacke.de> posted :
>McKirahan wrote:
>> "Kevin Humphreys" <khumphreys@hotmail.com> wrote in message
>> news:uYyOViCGFHA.1456@TK2MSFTNGP09.phx.gbl...
>>
>>>Hi there,
>>>Does anyone know a function on how to genetate the number in a given month
>>>and year.
>>>E.g. Month=March, Year=2005. Week count = 5
>>>Month=February, Year=2005. Week count = 4
>>
>>
>> What is your criteria for a "week"?
criterion

>> If you sum up the weeks in each month will it equal 52? 53? or what?



>I assume he's after the number of weeks a month spreads over aka
>rows in 7 columns calendars.

That does not agree with week-of-month numbering that matches ISO
8601:2000's week-of-year numbering.

> This script should be locale independent.

But ISTM that the results may need to depend on locale.




> FirstDayofMonth=DateAdd("d",1-day(MyDate),MyDate)
> LastDayofMonth=DateAdd("m",1,FirstDayofMonth)
> LastDayofMonth=DateAdd("d",-1,LastDayofMonth)
> WeeksInMonth=1+DateDiff("ww", FirstDayofMonth, LastDayofMonth, _
> FirstWeekDay, FirstWeekInYear)


ISTM that, whatever the definition of weeks-in-month, the result can
thereafter depend only on the day-of-month and day-of-week of the last
day of the month. So, for an alternative approach,

Y = Year(MyDate) : M = Month(MyDate)
LoM = DateSerial(Y, M+1, 0)
DoM = Date(LoM) : DoW = WeekDay(LoM) ' check defaults
...

For ISO-style, the next step is to get the day-of-month of the last
Thursday.


For the number of rows on the calendar, subtract the absolute week
counts of the last and first days and add 1; the absolute week number of
a date is Int(K + DateSerial(Y, M, D)/7) for K in 0..6 depending
on which is considered the first day of the week; which looks to be like
what the quoted code does.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.