get_last_day_of

The days_in_month statement sets a variable to contain the number of days in the specified month

Syntax

get_last_day_ofyyyyMMasvarName

Details

The get_last_day_of statement will set the value of the variable called varName to contain the number of days in the month specifed by yyyyMM where yyyy is a four-digit year and MM is a 2-digit month.

The statement will take leap years into account.

Example

#
# Check a specific date to see if it is the last day of a month
#
var somedate = 20180228
gosub detect_end_of_month(${somedate})
if (${is_last_day} == TRUE) {
print ${somedate} is the last day of a month
} else {
print ${somedate} is not the last day of a month
}
#
# Check todays date to see if it is the last day of the month
#
gosub detect_end_of_month()
if (${is_last_day} == TRUE) {
print Today is the last day of the month
} else {
print Today is not the last day of the month
}
# This subroutine determines whether a date is the last
# day of a month or not
#
# If no argument is provided it defaults to the current system
# time, else it uses the supplied yyyyMMdd format argument
#
# It sets a variable called 'is_last_day' to TRUE or FALSE
subroutine detect_end_of_month {
if (${SUBARG.COUNT} == 0) {
get_last_day_of ${YEAR}${MONTH} as last_day
if (${last_day} == ${DAY}) {
var is_last_day = TRUE
} else {
var is_last_day = FALSE
}
return
}
# Verify argument format
match date "^([0-9]{8})$" ${SUBARG_1}
if (${date.STATUS} != MATCH) {
print Error: the provided argument is not in yyyyMMdd format
terminate with error
}
# Get the day portion of the argument
match day "^[0-9]{6}([0-9]{2})$" ${SUBARG_1}
var day_to_check = ${day.RESULT}
# Get the yyyyMM portion of the argument
match yyyyMM "^([0-9]{6})" ${SUBARG_1}
var month = ${yyyyMM.RESULT}
get_last_day_of ${month} as last_day
if (${last_day} == ${day_to_check}) {
var is_last_day = TRUE
} else {
var is_last_day = FALSE
}
}