From:	SMTP%"langstoeger@venus.kapsch.co.at" 10-AUG-1993 09:51:44.98
To:	EVERHART
CC:	
Subj:	RE: Week of Year

From: langstoeger@venus.kapsch.co.at (peter langstoeger)
X-Newsgroups: comp.os.vms
Subject: RE: Week of Year
Date: 10 Aug 1993 11:41:23 GMT
Organization: <<< KAPSCH AG
Lines: 56
Message-ID: <2481h3$dd@theben.kapsch.co.at>
Reply-To: langstoeger@venus.kapsch.co.at
NNTP-Posting-Host: venus.kapsch.co.at
To: Info-VAX@KL.SRI.COM
X-Gateway-Source-Info: USENET

In article <0097082637DCB660.43E00082@satt.se>, "Ingemar Hansson, SattControl AB, Sweden" <irh@satt.se> writes:
>Joerg Oertel <OERTEL@immunbio.mpg.de> writes:
>
>>[...]
>>I had look into my calandar and discovered that the first three days of 1993
>>belong to the 53rd week of 1992, so the 1st week of 1993 started at Jan, 4.
>>
>>Does anybody know an algorithm or the rule to calculate the week of year?
>
>Week number one is the first week that has four or more days in it. That is, if 
>1 Jan is a Monday, Tuesday, Wednesday or Thursday.
>This is at least the case here in Sweden. I guess the same applies to you too.

I think it is the case in every country. But I don't know for sure.

Here is an example command file with two ways to calculate. We use it to start
our backup with various params. So it seems to work all times. I wrote it many
years ago, but can't remember all details. If you need help, please be patient.

$!*************************  Start of DATE2WEEK.COM  ************************
$!
$	date = p1
$	IF date .EQS. "" THEN date = "Today"
$	day  = F$CVTIME (date,,"DAY")
$	IF .NOT. $status THEN exit
$!
$	month= F$CVTIME (date,,"MONTH")
$	year = F$CVTIME (date,,"YEAR")
$	IF month .LE. 2
$	THEN
$	    yday = 31 * (month - 1) + day
$	ELSE
$	    yday = (306 * month - 324) / 10 + day + ((year-1)-(year-1)/4*4)/3
$	ENDIF
$!1.)
$	weekday	= F$EXTRACT (0, 2, F$CVTIME ("1-JAN-''year'",,"WEEKDAY"))
$	offset	= (F$LOCATE (weekday, "FrSaSuMoTuWeTh")/2) + 3	! from 3 to 9
$	week	= (yday + offset) / 7				! from 0 to 52
$	WRITE SYS$OUTPUT date, " is the ", yday, " day of the year, LW ''week'"
$!2.)
$	days	= (year-1)*365 + (year-1)/4 - (year-1)/100 + (year-1)/400 + 3
$	offset	= days - days/7*7 + 3				! from 3 to 9
$	week	= (yday + offset) / 7				! from 0 to 52
$	WRITE SYS$OUTPUT date, " is the ", yday, " day of the year, LW ''week'"
$!
$!**************************  End of DATE2WEEK.COM  *************************

Hope it helps other people start playing :-)

-Peter
--------------------------------------------------------------------------------
Peter "EPLAN" LANGSTOEGER        Tel.    +43 1 81111-2382
Network and VMS system manager   Fax.    +43 1 81111-888
Technical Computer Center (ADV)  E-mail  Peter.Langstoeger@kapsch.co.at
KAPSCH AG      Wagenseilgasse 1  PSImail PSI%(0232)281001141::Peter.Langstoeger
A-1121 VIENNA  AUSTRIA           "I'm not a pessimist, I am a realist"

