|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Calculations |
MiniRobotLanguage (MRL)
DTO.AddMonths Command
Add or Subtract Months from a Specific Date
Intention
The DTO.AddMonths command performs calendar-aware addition or subtraction of months from a given date. It intelligently handles the varying lengths of months and adjusts the day if the resulting month has fewer days than the original.
For example, adding one month to January 31st will correctly result in February 28th (or 29th in a leap year), not an invalid date like February 31st. This makes it perfect for calculating expiration dates, subscription renewals, or any date-based logic that spans across months.
Syntax
DTO.AddMonths|date|months|[format]|[$$RES]
Parameter Explanation
date - The starting date string (e.g., "31.01.2024").
months - The number of months to add. Use a negative number to subtract months.
format - (Optional) The format for both the input `date` and the resulting output string. If omitted, "DD.MM.YYYY" is assumed.
$$RES - (Optional) The variable to receive the newly calculated date string.
Example
'**********************************************
' DTO.AddMonths - Sample
'**********************************************
'
' --- Sample 1: Add 1 month to Jan 31st (Leap Year) ---
$$DAA = "31.01.2024"
DTO.AddMonths|$$DAA|1||$$RES
MBX.One month after $$DAA is $$RES ' Result: 29.02.2024
'
' --- Sample 2: Subtract 6 months ---
$$DAB = "15.08.2025"
DTO.AddMonths|$$DAB|-6||$$RES
MBX.Six months before $$DAB was $$RES ' Result: 15.02.2025
'
' --- Sample 3: Add 13 months (crossing a year boundary) ---
$$DAC = "20.10.2022"
DTO.AddMonths|$$DAC|13|DD-MM-YYYY|$$RES
MBX.Thirteen months after $$DAC is $$RES ' Result: 20-11-2023
ENR.
Remarks
The command correctly handles rollovers into the next or previous year. For example, adding 3 months to "15.11.2023" results in "15.02.2024".
Limitations:
An invalid date string as input will cause a parameter error.
See also:
• DTC. - Date and Time Calculation