RGUTDT ;CAIRO/DKM - FM date to formatted date;04-Sep-1998 12:46;DKM
;;2.1;RUN TIME LIBRARY;;Mar 22, 1999
;=================================================================
; Inputs:
; RGDAT = date to format (DHCP format or $H format)
; RGFMT = date and time format control (optional)
; xxx0 = dd-mmm-yyyy
; xxx1 = mmm dd,yyyy
; xxx2 = mm/dd/yyyy
; xxx3 = mm-dd-yyyy
; xx0x = hh:mm
; xx1x = hh:mm xx
; x0xx = use space to separate date/time
; x1xx = use @ to separate date/time
; 0xxx = allow leading zeros
; 1xxx = remove leading zeros
; Outputs:
; Returns formatted date
;=================================================================
ENTRY(RGDAT,RGFMT) ;
S RGDAT=$G(RGDAT,$H)
Q:'RGDAT ""
N RGZ1,RGZ2,RGZ3,RGZ4,RGDLM,RGTM
S:RGDAT?1.N1",".N RGDAT=$$HTFM^XLFDT(RGDAT)
S RGFMT=$G(RGFMT)#100000,RGFMT=RGFMT#10000,RGZ4=RGFMT\1000,RGFMT=RGFMT#1000,RGDLM=$S(RGFMT>99:"@",1:" "),RGFMT=RGFMT#100,RGTM=RGFMT\10,RGFMT=RGFMT#10
I RGDAT\1 D
.S RGZ3=RGDAT\1+17000000,RGZ1=$E(RGZ3,7,8),RGZ2=$E(RGZ3,5,6),RGZ3=$E(RGZ3,1,4)
.S:RGZ4 RGZ1=+RGZ1,RGZ2=+RGZ2
.S:RGFMT<2 RGZ2=$P("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",",",RGZ2)
.S RGZ1=$S('RGFMT:RGZ1_"-"_RGZ2_"-"_RGZ3,RGFMT=1:RGZ2_" "_RGZ1_","_RGZ3,RGFMT=2:RGZ2_"/"_RGZ1_"/"_RGZ3,1:RGZ2_"-"_RGZ1_"-"_RGZ3)
E S RGZ1=""
S RGZ2=RGDAT#1*10000+10000\1
I RGZ2=10000!(RGZ2>12400) S RGZ2=""
E D
.S:RGTM RGZ2=$S(RGZ2=12400:RGZ2-1200_" am",RGZ2>11299:RGZ2-1200_" pm",RGZ2>11199:RGZ2_" pm",RGZ2<10099:RGZ2+1200_" am",1:RGZ2_" am")
.S RGZ3=$S(RGZ4:+$E(RGZ2,2,3),1:$E(RGZ2,2,3)),RGZ2=RGZ3_":"_$E(RGZ2,4,8)
Q RGZ1_$S('$L(RGZ2):"",$L(RGZ1):RGDLM,1:"")_RGZ2
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HRGUTDT 1715 printed Nov 22, 2024@17:47:11 Page 2
RGUTDT ;CAIRO/DKM - FM date to formatted date;04-Sep-1998 12:46;DKM
+1 ;;2.1;RUN TIME LIBRARY;;Mar 22, 1999
+2 ;=================================================================
+3 ; Inputs:
+4 ; RGDAT = date to format (DHCP format or $H format)
+5 ; RGFMT = date and time format control (optional)
+6 ; xxx0 = dd-mmm-yyyy
+7 ; xxx1 = mmm dd,yyyy
+8 ; xxx2 = mm/dd/yyyy
+9 ; xxx3 = mm-dd-yyyy
+10 ; xx0x = hh:mm
+11 ; xx1x = hh:mm xx
+12 ; x0xx = use space to separate date/time
+13 ; x1xx = use @ to separate date/time
+14 ; 0xxx = allow leading zeros
+15 ; 1xxx = remove leading zeros
+16 ; Outputs:
+17 ; Returns formatted date
+18 ;=================================================================
ENTRY(RGDAT,RGFMT) ;
+1 SET RGDAT=$GET(RGDAT,$HOROLOG)
+2 if 'RGDAT
QUIT ""
+3 NEW RGZ1,RGZ2,RGZ3,RGZ4,RGDLM,RGTM
+4 if RGDAT?1.N1",".N
SET RGDAT=$$HTFM^XLFDT(RGDAT)
+5 SET RGFMT=$GET(RGFMT)#100000
SET RGFMT=RGFMT#10000
SET RGZ4=RGFMT\1000
SET RGFMT=RGFMT#1000
SET RGDLM=$SELECT(RGFMT>99:"@",1:" ")
SET RGFMT=RGFMT#100
SET RGTM=RGFMT\10
SET RGFMT=RGFMT#10
+6 IF RGDAT\1
Begin DoDot:1
+7 SET RGZ3=RGDAT\1+17000000
SET RGZ1=$EXTRACT(RGZ3,7,8)
SET RGZ2=$EXTRACT(RGZ3,5,6)
SET RGZ3=$EXTRACT(RGZ3,1,4)
+8 if RGZ4
SET RGZ1=+RGZ1
SET RGZ2=+RGZ2
+9 if RGFMT<2
SET RGZ2=$PIECE("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",",",RGZ2)
+10 SET RGZ1=$SELECT('RGFMT:RGZ1_"-"_RGZ2_"-"_RGZ3,RGFMT=1:RGZ2_" "_RGZ1_","_RGZ3,RGFMT=2:RGZ2_"/"_RGZ1_"/"_RGZ3,1:RGZ2_"-"_RGZ1_"-"_RGZ3)
End DoDot:1
+11 IF '$TEST
SET RGZ1=""
+12 SET RGZ2=RGDAT#1*10000+10000\1
+13 IF RGZ2=10000!(RGZ2>12400)
SET RGZ2=""
+14 IF '$TEST
Begin DoDot:1
+15 if RGTM
SET RGZ2=$SELECT(RGZ2=12400:RGZ2-1200_" am",RGZ2>11299:RGZ2-1200_" pm",RGZ2>11199:RGZ2_" pm",RGZ2<10099:RGZ2+1200_" am",1:RGZ2_" am")
+16 SET RGZ3=$SELECT(RGZ4:+$EXTRACT(RGZ2,2,3),1:$EXTRACT(RGZ2,2,3))
SET RGZ2=RGZ3_":"_$EXTRACT(RGZ2,4,8)
End DoDot:1
+17 QUIT RGZ1_$SELECT('$LENGTH(RGZ2):"",$LENGTH(RGZ1):RGDLM,1:"")_RGZ2