7 Date Conversion

Alternate Date Conversion

The United Kingdom and Australien date format (DD/MM/YY) is converted using the folowing algorithms.

! This function converts a date string of the form dd/mm/yy, d/mm/yy 
! dd/m/yy, or d/m/yy to an integer value.  The date must be 
! from 1/1/72 to 31/12/99 inclusive.  The integer value returned 
! will be in the range 1 to 10227.
! If an invalid date string is input,the return integer value 
! will k>e 0.
! variables:
! 	D	the day value
! 	Dt$	the date string
! 	Dval	the numeric value of the date
! 	I	a loop index
! 	M	the month value
! 	Y	the year value
!
       DEF FNDate(Dt$)
          INTEGER D,Dval,I,M,Y
!
! Check for proper date string length.
          IF (LEN(Dt$)<=8) AND (LEN(Dt$)=6) THEN Contl
          Dval=0
          GOTO End
! Insert leading zeros in month and day, if necessary, to 
! get mm/dd/yy.
Cont1:    IF LEN(Dt$)=6 THEN Dt$="O"&Dt$
          IF (LEN(Dt$)=7) AND (Dt$[2,2]="/") THEN Dt$="0"&Dt$
          IF LEN(Dt$)=7 THEN Dt$=Dt$[1,3]&"0"&Dt$[4]
!
! Check for slashes between month, day and year.
          IF (Dt$[3,3]="/") AND (Dt$[6,6]="/") THEN Cont2
          Dval=0
          GOTO End
!
! Check for only digits in month,day and year.
Cont2:    FOR I=1 TO 8
             IF (I=3) OR (I=6) THEN Cont3
             IF POS("1234567890",Dt$[I,I])>0 THEN Cont3
             Dval=0
             GOTO End
Cont3:    NEXT I
!
! Convert month, day and year to numeric.
          M=VAL(Dt$[1,2])
          D=VAL(Dt$[4,5])
          Y=VAL(Dt$[7,8])+1900
!
! Compute the numeric value of the date.
          Dval=INT(365.2500*(Y-1972)+0.75)+INT(30.550*M-29.950)
-2*(M>2)+D+((M>2)AND (Y/4=INT(Y/4)))
!
! Convert the numeric value of the date back to a string eck for
! valid date.
Cont4:    IF Dt$<>FNDate$(Dval) THEN Dval=0
End:      RETURN Dval
       FNEND
!
!
! This function converts a date integer vlaue in the range 1 to 10227
! to a date string of the form mm/dd/yy.  If an invalid date integer
! value is input, the date string will be set to null.
!
! variables:
!  D	 - the day value
!  Dt$	 - the date string
!  Dval -	the numeric value of the date
!  M	 - the month value
!  N	 - an intermediate value
!  Y	 - the year value
!
       DEF FNDate$(INTEGER Dval)
          INTEGER D,M,N,Y
          DIM Dt$[8]
!
! Check the numeric value for valid range.
          IF (Dval>0) AND (Dval<10228) THEN Contl
          Dt$=" "
          GOTO End
!
! Convert numeric value of the date to month, day and year.
Cont1:    Y=INT((Dval-L)/365.2500)+1972
          N=Dval-INT(365.2500-(Y-1972)+0.75)
          M=INT((N+31)/30)
          IF INT(30.550*M-29.950)-2*(M>2) AND ((Y/4=INT(Y/4))>=N) THEN 
M=M-L
          D=N-INT(30.550*M-29.950)+2*(M>2)-((M>2) AND (Y/4=INT(Y/4)))
! 
! Assemble the date string.
          Dt$=VAL$(D)&"/"&VAL$(M)&"/"&VAL$(Y-1900)
!
! Insert leading zeros in month and day, if necessary, to 
! get mm/dd/yy.
          IF LEN(Dt$)=6 THEN Dt$="O"&Dt$
          IF (LEN(Dt$)=7) AND (Dt$[2,2]="/") THEN Dt$="O"&Dt$
          IF LEN(Dt$)=7 THEN Dt$=Dt$[1,3]&"O"&Dt$[4]
End:      RETURN Dt$
       FNEND

Eloquence Query Manual - 19 DEC 2002