Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2012
    Posts
    44

    Unanswered: Question about date number format

    First of all, I had no idea where to post this question, so apologizes if this is wrong. I posted it here because it's in PHP I will use it.

    I'm familiar with the fact that a UNIX timestamp is the number of seconds from 1st Jan 1970.

    However, I now have data in a table that describes the persons birthdays in a 6-number format.

    For example, the number 145813 equal 1st March 1982. 145814 is 2nd March 1982.

    What is this? Is it a well-known format?

    Thanks for any help.

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    It is the number of days since an epoch date. Day one appears to be about Jan 1 1583, just after the start of the modern calendar.
    Here is a cobol program to calculate starting at 1900. Change the start date to 1600, or subtract a constant from your date to match the results from the following.
    You might have to make an allowance for 2000 being a leap year.
    Code:
          IDENTIFICATION DIVISION.
           PROGRAM-ID. XDATEX.
           AUTHOR. JACK TEARLE.
           DATE-WRITTEN. FEB 1983.
           REMARKS. CONVERT DATE TO DAY OF CENTURY FROM BASE JAN 1 1901.
                   VALID UNTIL DEC 31 1999.
                   INPUT IS DATE 9(8) IN MMDDYY FORMAT.
                   OUTPUT IS NUMBER OF DAYS SINCE JAN 1 1901 PIC S9(10).
                2. CONVERT DAY OF CENTURY TO DATE FROM BASE JAN 1 1901.
           *        VALID UNTIL DEC 31 1999.
    	             VALID AFTER Jan 1 1901
                   INPUT NUMBER OF DAYS SINCE JAN 1 1901
                   OUTPUT DATE 9(8) IN FORMAT MMDDYY.
                   OUTPUT DAY OF WEEK PIC 9, WHERE 1 IS SUNDAY AND 7 IS SATU
           ENVIRONMENT DIVISION.
           CONFIGURATION SECTION.
           SOURCE-COMPUTER. UNVIAC-1100.
           OBJECT-COMPUTER. UNIVAC-1100.
           DATA DIVISION.
           WORKING-STORAGE SECTION.
           01  CALC-YEAR PIC S9(10) COMP.
           01  CALC-MONTH PIC S9(10) COMP.
           01  CALC-DAY PIC S9(10) COMP.
           01  DYYR PIC S9(10) COMP.
           01  DYWK PIC S9(10) COMP.
           01  DYMO PIC S9(10) COMP.
           01  TEMP-YEAR PIC S9(10) COMP.
           01  TEMP-DAY PIC S9(10) COMP.
           01  LEAP-YEAR PIC S9(10) COMP.
           01  HOLD-DATE PIC X(8).
           01  DAY-NAME-DATA.
               03 FILLER PIC X(9) VALUE 'SUNDAY'.
               03 FILLER PIC X(9) VALUE 'MONDAY'.
               03 FILLER PIC X(9) VALUE 'TUESDAY'.
               03 FILLER PIC X(9) VALUE 'WEDNESDAY'.
               03 FILLER PIC X(9) VALUE 'THURSDAY'.
               03 FILLER PIC X(9) VALUE 'FRIDAY'.
               03 FILLER PIC X(9) VALUE 'SATURDAY'.
           01  DAY-NAME-TABLE REDEFINES DAY-NAME-DATA.
               03 DAY-NAME OCCURS 7 TIMES PIC X(9).
           01  MONTH-NAME-DATA.
               03 FILLER PIC X(9) VALUE 'JANUARY'.
               03 FILLER PIC X(9) VALUE 'FEBRUARY'.
               03 FILLER PIC X(9) VALUE 'MARCH   '.
               03 FILLER PIC X(9) VALUE 'APRIL   '.
               03 FILLER PIC X(9) VALUE 'MAY     '.
               03 FILLER PIC X(9) VALUE 'JUNE    '.
               03 FILLER PIC X(9) VALUE 'JULY    '.
               03 FILLER PIC X(9) VALUE 'AUGUST  '.
               03 FILLER PIC X(9) VALUE 'SEPTEMBER'.
               03 FILLER PIC X(9) VALUE 'OCTOBER  '.
               03 FILLER PIC X(9) VALUE 'NOVEMBER '.
               03 FILLER PIC X(9) VALUE 'DECEMBER '.
           01  MONTH-NAME-TABLE REDEFINES MONTH-NAME-DATA.
               03 MONTH-NAME OCCURS 12 TIMES PIC X(9).
           LINKAGE SECTION.
           01  DATE-CROSS-REFERENCE.
               02  CALENDAR-DATE.
                   03 CALENDAR-MONTH PIC 99.
                   03 CALENDAR-DAY PIC 99.
           *       03 CALENDAR-YEAR PIC 99.
    	           03 CALENDAR-YEAR PIC 9999.
               02  DAYS-SINCE-JAN-1901 PIC S9(10) COMP.
               02  DAY-OF-WEEK PIC S9.
               02  NAME-OF-DAY PIC X(9).
               02  NAME-OF-MONTH PIC X(9).
           PROCEDURE DIVISION USING DATE-CROSS-REFERENCE.
           SOJ.
               IF DAYS-SINCE-JAN-1901 NOT EQUAL ZERO
                   GO TO CENTURY-TO-CALENDAR.
               MOVE 2 TO LEAP-YEAR.
               MOVE CALENDAR-DATE TO HOLD-DATE.
            *  MOVE CALENDAR-YEAR TO CALC-YEAR.
    		   SUBTRACT 1900 FROM CALENDAR-YEAR GIVING CALC-YEAR.
               MOVE CALENDAR-MONTH TO CALC-MONTH.
               MOVE CALENDAR-DAY TO CALC-DAY.
               DIVIDE 4 INTO CALC-YEAR GIVING TEMP-YEAR.
               MULTIPLY 4 BY TEMP-YEAR.
               IF TEMP-YEAR EQUAL CALC-YEAR MOVE 1 TO LEAP-YEAR.
               MULTIPLY 275 BY CALC-MONTH GIVING DYYR.
               DIVIDE 9 INTO DYYR.
               ADD CALC-DAY TO DYYR.
               SUBTRACT 30 FROM DYYR.
               IF CALC-MONTH GREATER THAN 2
                   SUBTRACT LEAP-YEAR FROM DYYR GIVING DYYR.
               SUBTRACT 1 FROM CALC-YEAR GIVING DAYS-SINCE-JAN-1901.
               MULTIPLY 1461 BY DAYS-SINCE-JAN-1901.
               DIVIDE 4 INTO DAYS-SINCE-JAN-1901.
               ADD DYYR TO DAYS-SINCE-JAN-1901.
               PERFORM CENTURY-TO-CALENDAR.
               IF CALENDAR-DATE NOT EQUAL HOLD-DATE
                   MOVE ZERO TO DAYS-SINCE-JAN-1901
                                CALENDAR-DATE
                                DAY-OF-WEEK
                   MOVE SPACE TO NAME-OF-DAY
                                 NAME-OF-MONTH.
               GO TO EOJ.
           CENTURY-TO-CALENDAR.
               DIVIDE 1461 INTO DAYS-SINCE-JAN-1901 GIVING CALC-YEAR.
               SUBTRACT CALC-YEAR FROM DAYS-SINCE-JAN-1901 GIVING CALC-YEAR.
               ADD 364 TO CALC-YEAR.
               DIVIDE 365 INTO CALC-YEAR.
               SUBTRACT 1 FROM CALC-YEAR GIVING DYYR.
               MULTIPLY 1461 BY DYYR.
               DIVIDE 4 INTO DYYR.
               SUBTRACT DYYR FROM DAYS-SINCE-JAN-1901 GIVING DYYR.
               MOVE 2 TO LEAP-YEAR.
               DIVIDE 4 INTO CALC-YEAR GIVING TEMP-YEAR.
               MULTIPLY 4 BY TEMP-YEAR.
               IF TEMP-YEAR EQUAL CALC-YEAR MOVE 1 TO LEAP-YEAR.
               MOVE DYYR TO TEMP-DAY.
               SUBTRACT LEAP-YEAR FROM 61 GIVING TEMP-YEAR.
               IF TEMP-DAY GREATER THAN TEMP-YEAR
                   ADD TEMP-DAY LEAP-YEAR GIVING TEMP-DAY.
               MULTIPLY 9 BY TEMP-DAY GIVING CALC-MONTH.
               ADD 269 TO CALC-MONTH.
               DIVIDE 275 INTO CALC-MONTH.
               MULTIPLY CALC-MONTH BY 275 GIVING DYMO.
               DIVIDE 9 INTO DYMO.
               SUBTRACT 30 FROM DYMO.
               SUBTRACT DYMO FROM TEMP-DAY GIVING DYMO CALC-DAY.
               ADD 1 DAYS-SINCE-JAN-1901 GIVING DYWK.
               DIVIDE DYWK BY 7 GIVING TEMP-YEAR REMAINDER DYWK.
               ADD 1 DYWK GIVING DAY-OF-WEEK.
           *   MOVE CALC-YEAR TO CALENDAR-YEAR.
    	       ADD 1900 CALC-YEAR GIVING CALENDAR-YEAR.
               MOVE CALC-MONTH TO CALENDAR-MONTH.
               MOVE CALC-DAY TO CALENDAR-DAY.
               MOVE DAY-NAME (DAY-OF-WEEK) TO NAME-OF-DAY.
               MOVE MONTH-NAME (CALENDAR-MONTH) TO NAME-OF-MONTH.
           EOJ.
               EXIT PROGRAM.

  3. #3
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    I did a little testing. The program works correctly from Jan 1 1900 to Dec 31 2099 (because 2000 is a leap year.)
    If you need dates prior to 1900 then you will have to modify the calculation of what a leap year is so that 1700, 1800 and 1900 are not leap years.

  4. #4
    Join Date
    Feb 2012
    Posts
    44
    Quote Originally Posted by kitaman View Post
    I did a little testing. The program works correctly from Jan 1 1900 to Dec 31 2099 (because 2000 is a leap year.)
    If you need dates prior to 1900 then you will have to modify the calculation of what a leap year is so that 1700, 1800 and 1900 are not leap years.
    Thanks a lot for your reply!

    I've never worked with Cobol, so I'll try and do this in PHP instead.

    Thanks again.

  5. #5
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Quote Originally Posted by Haydn View Post
    Thanks a lot for your reply!

    I've never worked with Cobol, so I'll try and do this in PHP instead.

    Thanks again.
    This is the same program in DIBOL (DEC's answer to COBOL and FORTRAN)
    Code:
    .SUBROUTINE XDATEX
    DATEXREF,    A
    RECORD DATEREC
               CLDRDATE, D8
                   CLDRYEAR, D4 @CLDRDATE 
                   CLDRMTH,  D2 @CLDRDATE +4    
                   CLDRDAY , D2 @CLDRDATE +6
               DAYS1901, D10            
               DAYOFWK,  D1
               NAMOFDAY, A9      
               NAMOFMTH, A9      
    RECORD 
            CALCYEAR , 	D10 
            CALCMTH ,	D10
            CALCDAY , 	D10 
            DYYR , 		D10 
            DYWK , 		D10
            DYMO , 		D10 
            TEMPYEAR , 	D10 
            TEMPDAY , 	D10 
            LEAPYEAR , 	D10
            HOLDDATE , 	D8   
    	M, A8
            DAYDATA, 7A9, 'SUNDAY   ','MONDAY   ','TUESDAY  ','WEDNESDAY'
    &			,'THURSDAY ','FRIDAY   ','SATURDAY '
            MTHDATA, 12A9, 'JANUARY  ','FEBRUARY ','MARCH   ','APRIL   ',
    &			'MAY     ','JUNE    ','JULY    ','AUGUST  ',
    &			'SEPTEMBER','OCTOBER  ','NOVEMBER ','DECEMBER '
    PROC
    SOJ,
    	DATEREC=DATEXREF
    	HOLDDATE=CLDRDATE
    	IF (DAYS1901 .NE. 0) GO TO CENTOCLD
    	LEAPYEAR=2
    	CALCYEAR= CLDRYEAR - 1900
    	CALCMTH= CLDRMTH
    	CALCDAY= CLDRDAY
    	TEMPYEAR= CALCYEAR/4
    	TEMPYEAR= TEMPYEAR * 4
    	IF (TEMPYEAR .EQ. CALCYEAR)  LEAPYEAR=1
    	DYYR= (CALCMTH * 275)/9 + CALCDAY - 30
    	IF (CALCMTH .GT. 2) DYYR= DYYR -LEAPYEAR
    	DAYS1901= CALCYEAR - 1
    	DAYS1901= (DAYS1901 * 1461) / 4 + DYYR
    	CALL    CENTOCLD
    	IF (CLDRDATE .NE. HOLDDATE)
    		BEGIN
    			DAYS1901= 0
    			CLDRDATE= 0
    			DAYOFWK = 0
    			NAMOFDAY=  
    			NAMOFMTH=
    			DATEXREF=DATEREC
    			RETURN
    		END
    	RETURN
    CENTOCLD,
    	CALCYEAR=(DAYS1901/1461) 
    	CALCYEAR=(DAYS1901 - CALCYEAR + 364)/365
    	DYYR=((CALCYEAR - 1)*1461)/4
    	DYYR=DAYS1901-DYYR
    	LEAPYEAR= 2
            TEMPYEAR= CALCYEAR/4
            TEMPYEAR= TEMPYEAR * 4
    	IF (TEMPYEAR .EQ. CALCYEAR) LEAPYEAR=1
    	TEMPDAY= DYYR
    	TEMPYEAR= 61 - LEAPYEAR 
    	IF (TEMPDAY .GT. TEMPYEAR) TEMPDAY= TEMPDAY + LEAPYEAR
    	CALCMTH= (TEMPDAY * 9 + 269) / 275
    	DYMO= ((CALCMTH * 275) / 9) - 30
    	CALCDAY= TEMPDAY - DYMO
    	DYMO=CALCDAY
    	DYWK=DAYS1901 + 1
    	DYWK=DYWK-((DYWK/7)*7)+1
    	DAYOFWK=DYWK
    	CLDRYEAR = CALCYEAR + 1900
    	CLDRMTH= CALCMTH
    	CLDRDAY= CALCDAY
    	NAMOFDAY=  DAYDATA(DYWK)
    	NAMOFMTH=MTHDATA(CALCMTH)
    	DATEXREF=DATEREC
    	RETURN

  6. #6
    Join Date
    Feb 2012
    Posts
    44
    Thanks again!

    I did an own little function in PHP that gives back the date now. Not sure if it's well coded, but it works:

    PHP Code:
    function fixDate($number){
        
    $days_since_1910 $number 119513;//1 Jan 1910
        
    $year1910_unix mktime(000111910);
        
    $join_unix $year1910_unix + ($days_since_1910 3600 24);
        
    $joined_date date("j M Y"$join_unix);
        return 
    $joined_date;


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •