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.