Numbering weeks for the years of this century. An easy problem?

28টি ভিউ
প্রথম অপঠিত মেসেজটিতে চলে আসুন

Guillermo Sanchez

পড়া হয়নি,
২৪ মে, ২০০৮ ৩:৫৫:১৩ AM২৪/৫/০৮
প্রাপক
According to ISO 8601:2004(E), parr. 2.2.10 the a calendar week
number is defined as ordinal number which identifies a calendar week
within its calendar year according to the rule that the first calendar
week of a year is that one which includes the first Thursday of that
year and that the last calendar week of a calendar year is the week
immediately preceding the first calendar week of the next calendar year.

Could any body build a function for numbering the week for the years
this century?

A think it is not an easy problem (for instance teh solution given by
Excel sometime is wrong
A solution for period 2000-2027 is also wellcome. In this period the
53-week years are 2004, 2009, 2015, 2020, 2026;

Guillermo

Hans Michel

পড়া হয়নি,
২৬ মে, ২০০৮ ৬:২৬:২১ AM২৬/৫/০৮
প্রাপক
Guillermo:

A google search for ISO Week and Excel would yield lot of choices.

For Excel solution not using the WEEKNUM which they know is wrong function
see
http://msdn.microsoft.com/en-us/library/bb277364.aspx

Now if you take the following VB solution from that page:

Public Function IsoWeekNum(d1 As Date) As Integer
' Provided by Daniel Maher.
Dim d2 As Long
d2 = DateSerial(Year(d1 - Weekday(d1 - 1) + 4), 1, 3)
IsoWeekNum = Int((d1 - d2 + Weekday(d2) + 5) / 7)
End Function

Convert to Mathematica

ISOWeek[x_] := Module[{d2},
d2 = DateList[{ToExpression[
DateString[
DatePlus[
x, {(-(Flatten[
Position[{"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"},
DateString[DatePlus[x, {-1, "Day"}], {"DayName"}],
1]])[[1]] + 4), "Day"}], "Year"]], 1, 3, 0, 0, 0}];
IntegerPart[(DateDifference[d2, x] +
Flatten[
Position[{"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"},
DateString[d2, {"DayName"}], 1]][[1]] + 5)/7]
]
Use as follows
ISOWeek[DateList[{2000, 1, 1, 0, 0, 0}]]

Returns same value as VB solution, does not make it correct!

On this news group there have been solutions to get the equivalent of
excel's DateSerial. This vb solution has many dependencies on how Microsoft
calculates and serializes dates.

I have not tested the VB nor the Mathematica code translation enough to say
this is a solution but leave the rest to others. There is plenty of room for
improvement. Because translation from VB "Sunday" is first day of the week;
but in ISO "Monday" is first day.

Hans
Note other links
http://emr.cs.iit.edu/home/reingold/calendar-book/second-edition/

http://personal.ecu.edu/MCCARTYR/isowdcal.html

http://personal.ecu.edu/MCCARTYR/ISOwdALG.txt

http://www.probabilityof.com/excel.shtml

http://www.cpearson.com/excel/weeknum.htm
"Guillermo Sanchez" <guillerm...@hotmail.com> wrote in message
news:g18hl1$kcr$1...@smc.vnet.net...

সকলকে উত্তর দিন
লেখককে লিখে পাঠান
ফরওয়ার্ড করুন
0টি নতুন মেসেজ