udfIsFirstDayOfMonth
udfIsLastDayOfMonth
udfIsNthDayOfMonth
udfIsLastDayInMonth
bln udfIsFirstDayOfMonth (str)
bln udfIsLastDayOfMonth (str)
bln udfIsNthDayOfMonth (int, str)
bln udfIsLastDayInMonth (str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfIsFirstDayOfMonth (strYmdHms)
Return Int (ItemExtract (3, strYmdHms, ":")) == 1
; The function returns a boolean value of @FALSE (0) or @TRUE (1).
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfIsLastDayOfMonth (strYmdHms)
Return Int (ItemExtract (2, strYmdHms, ":")) != Int (ItemExtract (2, TimeAdd (strYmdHms, "0:0:1:0:0:0"), ":"))
; The function returns a boolean value of @FALSE (0) or @TRUE (1).
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfIsNthDayOfMonth (intDay, strYmdHms)
If intDay < 1 || intDay > 31
   Return Int (ItemExtract (2, strYmdHms, ":")) != Int (ItemExtract (2, TimeAdd (strYmdHms, "0:0:1:0:0:0"), ":"))
Else
   Return intDay == Int (ItemExtract (3, strYmdHms, ":"))
EndIf
; To refer to the "last day" of month use any intDay out of range 1..31, e. g. intDay=0 or intDay=32.
; The function returns a boolean value of @FALSE (0) or @TRUE (1).
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfIsLastDayInMonth (strYmdHms)
Return Int (ItemExtract (3, strYmdHms, ":")) == udfDaysInMonth (strYmdHms)
#EndFunction
; The function returns a boolean value of @FALSE (0) or @TRUE (1).
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfDaysInMonth (strYmdHms)
intDaysInMonth = ItemExtract (ItemExtract (2, strYmdHms, ":"), "31,28,31,30,31,30,31,31,30,31,30,31", ",")
If intDaysInMonth == 28 Then intDaysInMonth = intDaysInMonth + udfIsLeapYear (strYmdHms)
Return intDaysInMonth
;..........................................................................................................................................
; The return value is an integer number in the range 28..31.
;
; Detlev Dalitz.20010325.20090726.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfIsLeapYear (strYmdHms)
intYear = Int (ItemExtract (1, strYmdHms, ":"))
Return !(intYear mod 4) && (!!(intYear mod 100) || !(intYear mod 400))
;..........................................................................................................................................
; This user defined function "udfIsLeapYear" determines wether the given year is a leap year or not.
; Based on the Gregorian calendar, first established in 1582 by Pope Gregory XIII.
; The function returns a boolean value of @FALSE (0) or @TRUE (1).
;
; Detlev Dalitz.20010325.20090725.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

; udfIsFirstDayOfMonth (strYmdHms)
blnIsFirstDayOfMonth1 = udfIsFirstDayOfMonth ("2008:02:29") ; @FALSE.
blnIsFirstDayOfMonth2 = udfIsFirstDayOfMonth ("2008:02:30") ; @FALSE.
blnIsFirstDayOfMonth3 = udfIsFirstDayOfMonth ("2008:03:01") ; @TRUE.
blnIsFirstDayOfMonth4 = udfIsFirstDayOfMonth (TimeYmdHms ()) ; ?

; udfIsLastDayOfMonth (strYmdHms)
blnIsLastDayOfMonth1 = udfIsLastDayOfMonth ("2008:02:28") ; @FALSE.
blnIsLastDayOfMonth2 = udfIsLastDayOfMonth ("2008:02:29") ; @TRUE.
blnIsLastDayOfMonth3 = udfIsLastDayOfMonth (TimeYmdHms ()) ; ?

; udfIsNthDayOfMonth (intDay, strYmdHms)
blnIsNthDayOfMonth1 = udfIsNthDayOfMonth (1, "2008:02:01")  ; @TRUE.
blnIsNthDayOfMonth2 = udfIsNthDayOfMonth (1, "2008:02:02")  ; @FALSE.
blnIsNthDayOfMonth3 = udfIsNthDayOfMonth (31, "2008:02:29") ; @FALSE.
blnIsNthDayOfMonth4 = udfIsNthDayOfMonth (0, "2008:02:29")  ; @TRUE.


; udfIsLastDayInMonth (strYmdHms)
blnIsLastDayInMonth1 = udfIsLastDayInMonth ("2008:02:28") ; @FALSE.
blnIsLastDayInMonth2 = udfIsLastDayInMonth ("2008:02:29") ; @TRUE.
blnIsLastDayInMonth3 = udfIsLastDayInMonth ("2008:02:30") ; @FALSE.
blnIsLastDayInMonth4 = udfIsLastDayInMonth (TimeYmdHms ()) ; ?

Exit