Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Routines 2

Status
Not open for further replies.

RASI

Programmer
Aug 29, 1998
29
0
0
US
Does anyone have a solution for finding the Month of the year if you know the Year Number and Week No.

Note: The compiler that I'm using does not have many of the new fancy date functions found in newer cobol compilers. I need to be able to calculate this using old fashion logic.
I'm using Realia 4.2

What I have: Year = 2003 and so on....
Week No = 23

What I need: Logic that will calculate the correct Month for any given week number for any given year.
This must consider leap years and all of the normal calendar rules.


Thanks,
Rick


 
I strongly recommend the following to any programmer:

Calendrical Calculations
Dershowitz and Reingold
Cambridge University Press
ISBN 0-521-56474-3

While I have no logic to offer, it would seem clear that week number can be fairly easily cast to a day number, but which day of the week do you use, since a week may span two months? Is a week defined to start on a specific day, or on the day which begins the year? Is the first week week 1 or week 0? Tom Morrison
 
Surely this is not possible as a week can encompass more than one month, or have I misunderstood?

Do you require the month of the first day of the week or something similar?

Marc
 
Whilst I think of it, do you mean any date (15th century, 16th century) or is there a date that it is invalid to go back beyond?
 
The following code assumes that the week starts on January 1. Other than that, it is good through the year 9999.
Code:
      01  DAY-OF-YEAR             PIC 9(04) COMP-5.
      01  LEAP-JUNK               PIC 9(04) COMP-5.
      01  LEAPX                   PIC 9(02) COMP-5.
          88  IS-LEAP                              VALUE 1.
      01  MOX                     PIC 9(02) COMP-5.
      01  DAYS-B4-TABLE COMP-5.
          05                      PIC 9(04) VALUE ZERO.
          05                      PIC 9(04) VALUE  31.
          05                      PIC 9(04) VALUE  60.
          05                      PIC 9(04) VALUE  91.
          05                      PIC 9(04) VALUE 121.
          05                      PIC 9(04) VALUE 152.
          05                      PIC 9(04) VALUE 182.
          05                      PIC 9(04) VALUE 213.
          05                      PIC 9(04) VALUE 244.
          05                      PIC 9(04) VALUE 274.
          05                      PIC 9(04) VALUE 305.
          05                      PIC 9(04) VALUE 335.
          05                      PIC 9(04) VALUE ZERO.
          05                      PIC 9(04) VALUE  31.
          05                      PIC 9(04) VALUE  59.
          05                      PIC 9(04) VALUE  90.
          05                      PIC 9(04) VALUE 120.
          05                      PIC 9(04) VALUE 151.
          05                      PIC 9(04) VALUE 181.
          05                      PIC 9(04) VALUE 212.
          05                      PIC 9(04) VALUE 243.
          05                      PIC 9(04) VALUE 273.
          05                      PIC 9(04) VALUE 304.
          05                      PIC 9(04) VALUE 334.
      01  REDEFINES DAYS-B4-TABLE.
          05  OCCURS 2 TIMES.
              10  DAYS-B4  COMP-5 PIC 9(04) OCCURS 12 TIMES.
      01  WS-YEAR                 PIC 9(04).
      01  REDEFINES WS-YEAR.
          05  WS-CC               PIC 9(02).
          05  WS-YY               PIC 9(02).
      01  WS-MONTH                PIC 9(02).
      01  WS-DAY                  PIC 9(02).
      01  WS-WEEK                 PIC 9(02).

       . . .

           COMPUTE DAY-OF-YEAR = WS-WEEK * 7 - 6
           MOVE WS-YY                    TO LEAPX
           IF LEAPX = ZERO
               MOVE WS-CC                TO LEAPX
           END-IF
           DIVIDE 4                    INTO LEAPX
                                     GIVING LEAP-JUNK
                                  REMAINDER LEAPX
           ADD 7                         TO LEAPX
           DIVIDE 4                    INTO LEAPX
           If WS-YEAR = 4000 OR 8000
               MOVE 1                    TO LEAPX
           End-If
           PERFORM VARYING MOX FROM 12 BY -1
                     UNTIL DAYS-B4(LEAPX,MOX) < DAY-OF-YEAR
               CONTINUE
           END-PERFORM
           SUBTRACT DAYS-B4(LEAPX,MOX) FROM DAY-OF-YEAR
                                     GIVING WS-DAY
           MOVE MOX                      TO WS-MONTH
           .
If the week starts on a specific weekday, you need to know which day and and what to do with the week that starts in on year and ends in the next.
 
I just remembered. This code is good only for the Gregorian calendar, which started being used sometime in the 17th or 18th century. (The starting date is different for diffent countries.) Before that, the Julian calendar was being used, which is simpler to calculate but is slightly inacurate (about 3/4 day every hudred years).
 
How about creating a file that has the week numbers and dates in it? Then, access the file by week number to get the relevant info. I've been at a few clients that use a file. Most of them were manufacturing companies and included other info. in the record such as bar code and week color.

Just a thought.

Tom.
 
Hello:

I use RMCOBOL - 85 Version 8 on Linux.

I want to compare a YYMMDD date field to the SDATE field that I ACCEPT from my system.

I want to validate that a date sent into my application is Less than 10 days old of the current date.

I figure that the easiest math for this would be able to simply convert my YYMMDD dates to Julian Dates(which are simply defined as the number of the day in the year i.e. 01/21/2003 is just 021, and 02/02/2003 is 31+2 = 033).

Then I could simply subtract the date I'm testing(in Julian date format) from the system date(today's date in Julian date format) and go from there.

Is there any RMCOBOL features that would make this easy, or possibly a subroutine someone has already built?

Thanks.
-David
 
RM/COBOL does not have any supplied function to help you with this

There was a set of routines from ETK that would allow you do to this.
Name of the program is CALRPK but I am not sure were you can get it now as it seems that is down. (I have it)





Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top