Determine the Last Day of a Month

From HotDocs Wiki

Jump to: navigation, search

Some templates may require calculating the last day of a given month. For example, a template may contain a Date variable for an individual's date of death. In the same template, you may need to calculate 12 months after the date of death, then find the last day of the previous month. If the date of death is April 7, 2003, the date to be calculated is March 31, 2004.

To find the last day of a given month, the easiest approach is to find the first day of the following month, and then subtract one day to find the last day of the previous month.

Example

The following computations show how to determine the last day of a month. The first computation uses the DATE OF expression to find the first day of the month one year after a given date, and then subtracts one day. The second computation finds the last day of the current month by finding the first day of the next month, and then subtracting a day.

In these examples, Date Var is any Date variable:

//Example 1: Find the last day of the previous month one year from a date.
Date Var + 1 YEAR
DATE OF( 1, MONTH OF( RESULT ), YEAR OF( RESULT ) )
RESULT - 1 DAY
 
//Example 2: Find the last day of the current month.
TODAY + 1 MONTH
DATE OF( 1, MONTH OF( RESULT ), YEAR OF( RESULT ) )
RESULT - 1 DAY