;------------------------------------------------------------------------------------------------------------------------------------------ #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 udfDaysInYear (strYmdHms) Return 365 + udfIsLeapYear (strYmdHms) ;.......................................................................................................................................... ; The return value is an integer number in the range 365..366. ; ; 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. intDaysInMonth_2000_01 = udfDaysInMonth ("2000:01:01") ; 31. intDaysInMonth_2000_02 = udfDaysInMonth ("2000:02:01") ; 29. intDaysInMonth_2001_02 = udfDaysInMonth ("2001:02:01") ; 28. intDaysInMonth_Now = udfDaysInMonth (TimeYmdHms ()) intDaysInYear_2000 = udfDaysInYear (2000) ; 366. intDaysInYear_2001 = udfDaysInYear (2001) ; 365. intDaysInYear_Now = udfDaysInYear (TimeYmdHms ()) Exit