Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
FUNCTION bo_dttm && break out date and time from timestamp
PARAMETER zx_DtTm
* Notes: zx_DtTm is either a number or a character string representing
number
* Returns: Character String w/ "MM/DD/YYYY HH:MM:SS xM"
* or Error message
* [Change lcMsg at end of procedure to generate alternate output]
*
* Example: ? bo_dttm(510165755)
* ? bo_dttm("510165755")
*
PRIVATE lnDtTm, lnYear, lnMonth, lnDay, lnHour, lnMinute, lnSecond, lcAMPM
PRIVATE llOK, lcMsg
llOK = .T.
lcMsg = ""
IF TYPE('zx_DtTm') = "N"
lnDtTm = INT(zx_DtTm)
ELSE
IF TYPE('zx_DtTm') = "C"
lnDtTm = INT(VAL(zx_DtTm))
ELSE
llOK = .F.
ENDIF
ENDIF
DO WHILE llOK && not really a LOOP - just a way to handle errors more easily
lnSecond = MOD(lnDtTm, 32) * 2
IF !BETWEEN(lnSecond, 0, 60)
lcMsg = "Seconds out of range"
llOK = .F.
EXIT && a way out
ENDIF
lnDtTm = INT(lnDtTm/32)
lnMinute = MOD(lnDtTm, 64)
IF !BETWEEN(lnMinute, 0, 60)
lcMsg = "Minutes out of range"
llOK = .F.
EXIT && a way out
ENDIF
lnDtTm = INT(lnDtTm/64)
lnHour = MOD(lnDtTm, 32)
IF !BETWEEN(lnHour, 0, 24)
lcMsg = "Hours out of range"
llOK = .F.
EXIT && a way out
ENDIF
lcAMPM = "am"
DO CASE
CASE BETWEEN(lnHour,0,11)
* good enuff
CASE lnHour=12
lcAMPM = "pm"
CASE BETWEEN(lnHour,13,24)
lcAMPM = "pm"
lnHour = lnHour - 12
ENDCASE
lnDtTm = INT(lnDtTm/32)
lnDay = MOD(lnDtTm, 32)
IF !BETWEEN(lnDay, 1, 31)
lcMsg = "Day out of range"
llOK = .F.
EXIT && a way out
ENDIF
lnDtTm = INT(lnDtTm/32)
lnMonth = MOD(lnDtTm, 16)
IF !BETWEEN(lnMonth, 1, 12)
lcMsg = "Month out of range"
llOK = .F.
EXIT && a way out
ENDIF
lnDtTm = INT(lnDtTm/16)
lnYear = lnDtTm+1980
EXIT
ENDDO
IF llOK
lcMsg = transform(lnMonth,"@L 99")+"/" ;
+transform(lnDay,"@L 99")+"/" ;
+transform(lnYear,"@L 9999")+" " ;
+transform(lnHour,"@L 99")+":" ;
+transform(lnMinute,"@L 99")+":" ;
+transform(lnSecond,"@L 99")+" " ;
+lcAMPM
ENDIF
RETURN lcMsg