|
The following article was printed in September 1979 of the magazine „BYTE".
|
Two BASIC programs calculating a day of week as well as elapsed time between dates1.
|
|
Day of Week and Elapsed Time Programs
W B Agocs, Dept of Physical Sciences
Kutztown State College, Kutztown PA 19530
|
The day of the week, the number of elapsed days of a year, and the number of days between 2 dates are information that is required frequently in various types of analyses.
The term m is the month number minus 2.
If the month is January or February, m is 11 or 12 of the previous year.
K is the day of the month; C is the century, and Y is the year of the century.
The value of the square brackets is defined as the integer part of the result of evaluating the interior expression.
Day of Week From Date
The program is so written that corrections to month 11 or 12 of the previous year are made automatically if the month is January (1), or February (2).
The program is shown in
listing 1.
Century selection could have been incorporated, but the program is designed for the 20th Century.
Once the number of the day of the week is obtained (with Sunday being day 1), the date and the day are printed.
Matrix Elapsed Time Determination2
The use of a 12 by 31 matrix seems to be the most logical method for determining the elapsed days of a year, the remaining days in a year, and the day interval between 2 dates.
The program for such a determination is shown in
listing 2.
The
MAT A = CON statement in line 50 sets each element of the matrix equal to 1.
The subroutine in statements 440 thru 540 enters 0s into the matrix elements which correspond to the months with less than 31 days, and then fills the matrix elements with the date's numerical location in the year.
Thus on return from the subroutine, the days elapsed may be
printed between statements 180 and 190, or between statements 400 and 410 if desired.
Leap year corrections are made at lines 270 and 440.
Finally, if the interval between the 2 dates is less than or greater than a year (as determined by statement 100), the correct year increment is made in statements 230 and 280.
The total time interval is determined in statement 180 or 410, and the result printed at statement 190.
The matrix procedure, with correction for appropriate holidays, can be used in conjunction with stock market studies when knowledge of the market day interval is desired, or when determining if a particular date is a market trading day.
Listing 2:
BASIC program for using a matrix to determine the elapsed time between 2 dates.
[Original BASIC source and M(allard) BASIC source.
The customized source prints a modified format of the date.
The statement MAT A=CON in line 50 will be found as a subroutine in line 600 for both sources] |
|
|
| 1. |
The calculation of the leap year in the original sources was faulty.
E.g. the year 1900 was stated as leap year.
A proper calculation may be found at Wann ist Ostern ? (Easter, when is it?) for example.
I coded both programs for Turbo-Pascal as well as for Z80 assembler:
Day of Week From Date for Pascal and Assembler, together with
Matrix Elapsed Time Determination for Pascal and Assembler.
 |
| 2. |
A tool called DAYS.C may be found in the SIG-M (Volume 212, CP-M Plus Utilities and Misc. Routines dated 1985, January 18).
The function accepts a 6 digit ASCII argument ddmmyy and returns a number of days from 1.1.1900.
 |
Scanned by
Werner Cirsovius
September 2012
© BYTE Publications Inc.