# 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_of`***`yyyyMM`***`as`***`varName`*

## 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
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://olddocs.exivity.io/2.10.2/data-pipelines/extract/language/get_last_day_of.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
