Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

REXX Calculate Week No. from Current date

457 views
Skip to first unread message

Jay Pillai

unread,
Jan 17, 2000, 3:00:00 AM1/17/00
to
Hello

I am sure somebody out there can help me. I would like to work out the week
number from the current date.
For example if the current day happens to be the 20th of Jan 2000, the
week number will be 3
( because week 3 is from 17th to 23rd of Jan 2000) and for 16th of Feb the
week will be 7.
In short from the current date , it should be possible to determine to
which week the particular date belongs.

Thank you in advance

Jay

Nurmi, Seppo

unread,
Jan 18, 2000, 3:00:00 AM1/18/00
to
Hi!
This is a tricky one. I do not know if all countries have the same numbering
for weeks of year. A far as I know there is no rule that says which day the
week number 1 starts, because sometimes there is 53 weeks in a year, and
sometimes 52, and the last/first week kan reach over the newyear day. What I
would do is making a small table of years and the date when week nr 1
starts. Then would I simply calculate the number of days from that day
modulo 7.

This approach would work for several years in future, but it is not as neat
as a pure mathematical formula. It would be interesting to learn if such a
formula exists, and if the "week of year" number differs in different
countries. In Sweden we regularly plan meetings and such a things using week
numbers in stead of dates, so this is quite an important issue for us.
Seppo Nurmi
Sveriges Riksbank
Stockholm
Sweden

> -----Ursprungligt meddelande-----
> Från: Jay Pillai [SMTP:Jay_P...@SWISSRE.COM]
> Skickat: den 17 januari 2000 20:29
> Till: TSO-...@VM.MARIST.EDU
> Ämne: REXX Calculate Week No. from Current date

Krause, Michael

unread,
Jan 18, 2000, 3:00:00 AM1/18/00
to
Hello,

here's my solution:

/* rexx */
select
when date("w",date(d) - (date(d) - 1),"d") = "Monday" ,
& date("d") // 7 > 0 then
do
week = date(d) % 7 + 1
end
when date("w",date(d) - (date(d) - 1),"d") = "Tuesday" then
do
week = date(d) % 7 + 1
end
when date("w",date(d) - (date(d) - 1),"d") = "Wednesday" ,
& date("d") // 7 = 6 then
do
week = date(d) % 7 + 2
end
when date("w",date(d) - (date(d) - 1),"d") = "Wednesday" ,
& date("d") // 7 < 6 then
do
week = date(d) % 7 + 1
end
when date("w",date(d) - (date(d) - 1),"d") = "Thursday" ,
& date("d") // 7 < 4 then
do
week = date(d) % 7 + 2
end
when date("w",date(d) - (date(d) - 1),"d") = "Thursday" ,
& date("d") // 7 >= 4 then
do
week = date(d) % 7 + 1
end
when date("w",date(d) - (date(d) - 1),"d") = "Friday" ,
& date("d") // 7 >= 4 then
do
week = date(d) % 7 + 1
end
when date("w",date(d) - (date(d) - 1),"d") = "Saturday" ,
& date("d") // 7 >= 3 then
do
week = date(d) % 7 + 1
end
when date("w",date(d) - (date(d) - 1),"d") = "Sunday" ,
& date("d") // 7 >= 2 then
do
week = date(d) % 7 + 1
end
otherwise
do
week = date(d) % 7
end
end
say week
exit

____________________________________________________
Mit freundlichen Gruessen/Best regards

REWE-Informations-Systeme GmbH
Michael Krause
RIS/LIBS - NRZ - Raum 14
Raiffeisenstrasse 5-9
D-61191 Rosbach vor der Hoehe

Telefon: 0049(0)6003/85-2877
0049(0)6101/542 444 (privat)
Telefax: 0049(0)6003/85-6-2877
eMail: Michael...@rewe.de (Office)
Michael...@rhein-main.net (Home)

Krause, Michael

unread,
Jan 18, 2000, 3:00:00 AM1/18/00
to
Hi, Seppo

The rule for Germany is: Monday is first day in week and the first 4-day
week is week 1 in new year.

I think, this is the rule for European Community.

Michael

____________________________________________________
Mit freundlichen Gruessen/Best regards

REWE-Informations-Systeme GmbH
Michael Krause
RIS/LIBS - NRZ - Raum 14
Raiffeisenstrasse 5-9
D-61191 Rosbach vor der Hoehe

Telefon: 0049(0)6003/85-2877
0049(0)6101/542 444 (privat)
Telefax: 0049(0)6003/85-6-2877
eMail: Michael...@rewe.de (Office)
Michael...@rhein-main.net (Home)

> Ämne: REXX Calculate Week No. from Current date

Ralf Stork

unread,
Jan 18, 2000, 3:00:00 AM1/18/00
to
Hi Michael,

> The rule for Germany is: Monday is first day in week and the first 4-day
> week is week 1 in new year.
>
> I think, this is the rule for European Community.

are you sure? Did you derive this from any norming (DIN or its
successor)?

As far as I know, week number "1" is the week with the first Wednesday
of the year.

Ralf

Birger Heede (IBM Global Services)

unread,
Jan 19, 2000, 3:00:00 AM1/19/00
to

"Krause, Michael" wrote:

> Hi, Seppo


>
> The rule for Germany is: Monday is first day in week and the first 4-day
> week is week 1 in new year.
>
> I think, this is the rule for European Community.
>

True (week with 4 days)

ISO 8601 defines this. The week with first Thursday.

--
Birger Heede
IBM Global Services, Denmark

Danny Wilms

unread,
Jan 4, 2024, 6:36:34 AM1/4/24
to
Op woensdag 19 januari 2000 om 09:00:00 UTC+1 schreef Birger Heede (IBM Global Services):
Call Function 'Weeknummer' with the day, month and year (2 chars) ; the result is the weeknumber
example :
SAY weeknummer(31 12 11)

WeekNummer:
PARSE ARG wzwnd wzwno wzwny
wzwnz = '20'wzwny !! RIGHT(wzwno,2,'0') !! RIGHT(wzwnd,2,'0')
wzwnz = DATE('B',wzwnz,'S')
wzwn1 = DATE('B','20'wzwny'0101','S')
wzwn2 = ((wzwn1 + 3) // 7)
wzwn0 = wzwn1 - wzwn2 + 3
wzf = 0
IF wzwnz < wzwn0 THEN
DO
wzf = 1
wzwnz = DATE('B','20'RIGHT(wzwny - 1,2,'0')'1231','S')
wzwn1 = DATE('B','20'RIGHT(wzwny - 1,2,'0')'0101','S')
wzwn2 = ((wzwn1 + 3) // 7)
wzwn0 = wzwn1 - wzwn2 + 3
END
wzwnw = ((wzwnz - wzwn0) % 7) + 1
IF wzwnw > 52 &,
wzf = 0 THEN
DO
wzwn1 = DATE('B','20'RIGHT(wzwny + 1,2,'0')'0101','S')
wzwn2 = ((wzwn1 + 3) // 7)
wzwn9 = wzwn1 - wzwn2 + 3
IF wzwnz >= wzwn9 THEN
DO
wzwn0 = wzwn9
wzwnw = 1
END
END
RETURN wzwnw
0 new messages