udfGetYmd
udfGetHms
udfSetYmd
udfSetHms
str udfGetYmd (str)
str udfGetHms (str)
str udfSetYmd (str, str)
str udfSetHms (str, str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfGetYmd (strYmdHms)
Return StrSub (TimeSubtract (TimeAdd ("0000:1:1", strYmdHms), "0000:1:1"), 1, 10) ; Make valid datetime string
; This user defined function "udfGetYmd" returns the normalized "Ymd" date part of the given strYmdHms.
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfGetHms (strYmdHms)
Return StrSub (TimeSubtract (TimeAdd ("0000:1:1", strYmdHms), "0000:1:1"), 12, -1) ; Make valid datetime string
; This user defined function "udfGetHms" returns the normalized "Hms" date part of the given strYmdHms.
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfSetYmd (strYmdHms, strYmd)
strYmdHms = ItemReplace (ItemExtract (1, strYmd, ":"), 1, strYmdHms, ":")
strYmdHms = ItemReplace (ItemExtract (2, strYmd, ":") - 1, 2, strYmdHms, ":") ; Minus one month, will be added again.
strYmdHms = ItemReplace (ItemExtract (3, strYmd, ":") - 1, 3, strYmdHms, ":") ; Minus one day, will be added again.
Return TimeAdd ("0000:1:1:0:0:0", strYmdHms) ; Make valid datetime string
; This user dedined function "udfSetYmd" sets the "Ymd" date part of the given strYmdHms to the specified strYmd date value.
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfSetHms (strYmdHms, strHms)
strYmdHms = ItemReplace ("0", 4, strYmdHms, ":")
strYmdHms = ItemReplace ("0", 5, strYmdHms, ":")
strYmdHms = ItemReplace ("0", 6, strYmdHms, ":")
Return TimeAdd (strYmdHms, "0000:0:0:" : strHms) ; Make valid datetime string
; This user dedined function "udfSetHms" sets the "Hms" date part of the given strYmdHms to the specified stHms date value.
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

strYmd11 = udfGetYmd (TimeYmdHms ()) ; e. g. "2009:07:27".
strHms11 = udfGetHms (TimeYmdHms ()) ; e. g. "08:25:36".

strYmd21 = udfGetYmd ("0:5:4:3:2:1")    ; e. g. "0000:05:04".
strYmd22 = udfGetYmd ("2009:5:4:3:2:1") ; e. g. "2009:05:04".
strHms22 = udfGetHms ("2009:5:4:3:2:1") ; e. g. "03:02:01".

strYmdHms31 = udfSetYmd (TimeYmdHms (), "2004:10:05")  ; Set the date part.
strYmdHms32 = udfSetYmd (TimeYmdHms (), "2004:18:37")  ; Set the date part to "2005:07:07", leaves Hms as is.

strYmdHms41 = udfSetHms (TimeYmdHms (), "11:55:00")    ; Set the time part.
strYmdHms42 = udfSetHms (TimeYmdHms (), "48:120:1800") ; Set the date and time part to (2 days + 2 hours + 30 minutes) into the future.

Exit