Search…
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

1
#
2
# Check a specific date to see if it is the last day of a month
3
#
4
var somedate = 20180228
5
gosub detect_end_of_month(${somedate})
6
7
if (${is_last_day} == TRUE) {
8
print ${somedate} is the last day of a month
9
} else {
10
print ${somedate} is not the last day of a month
11
}
12
13
#
14
# Check todays date to see if it is the last day of the month
15
#
16
gosub detect_end_of_month()
17
if (${is_last_day} == TRUE) {
18
print Today is the last day of the month
19
} else {
20
print Today is not the last day of the month
21
}
22
23
# This subroutine determines whether a date is the last
24
# day of a month or not
25
#
26
# If no argument is provided it defaults to the current system
27
# time, else it uses the supplied yyyyMMdd format argument
28
#
29
# It sets a variable called 'is_last_day' to TRUE or FALSE
30
31
subroutine detect_end_of_month {
32
33
if (${SUBARG.COUNT} == 0) {
34
get_last_day_of ${YEAR}${MONTH} as last_day
35
36
if (${last_day} == ${DAY}) {
37
var is_last_day = TRUE
38
} else {
39
var is_last_day = FALSE
40
}
41
return
42
}
43
44
# Verify argument format
45
match date "^([0-9]{8})quot; ${SUBARG_1}
46
if (${date.STATUS} != MATCH) {
47
print Error: the provided argument is not in yyyyMMdd format
48
terminate with error
49
}
50
51
# Get the day portion of the argument
52
match day "^[0-9]{6}([0-9]{2})quot; ${SUBARG_1}
53
var day_to_check = ${day.RESULT}
54
55
# Get the yyyyMM portion of the argument
56
match yyyyMM "^([0-9]{6})" ${SUBARG_1}
57
var month = ${yyyyMM.RESULT}
58
59
get_last_day_of ${month} as last_day
60
61
if (${last_day} == ${day_to_check}) {
62
var is_last_day = TRUE
63
} else {
64
var is_last_day = FALSE
65
}
66
}
Copied!
Last modified 2yr ago
Export as PDF
Copy link