|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Calculations |
MiniRobotLanguage (MRL)
DTO.SubtractMonths Command
Subtract Months from a Date
Intention
The DTO.SubtractMonths command (alias submon) is used for date calculations, specifically to subtract a given number of months from a date. The command correctly handles rolling back over year boundaries.
For example, subtracting 3 months from February 15, 2024, will correctly result in November 15, 2023. This is useful for calculating past dates, such as finding a warranty expiration date or a 3-month-prior notification date.
Syntax
DTO.SubtractMonths|date|months|[format]|[$$RES]
Parameter Explanation
date - The source date string (e.g., "15.02.2024") or a variable containing one.
months - The integer number of months to subtract from the date.
format - (Optional) The format mask for the input `date` and the resulting output date.
$$RES - (Optional) The variable to store the resulting date. If omitted, the source variable provided in `date` is updated.
Example
'**********************************************
' DTO.SubtractMonths - Sample
'**********************************************
'
' Set the starting date.
$$DAA = "15.02.2024"
' Define how many months to subtract.
$$NUM = 3
' Perform the subtraction and store the new date in $$RES.
DTO.SubtractMonths|$$DAA|$$NUM||$$RES
' Display the result.
MBX.Original: $$DAA | Result: $$RES
' Expected output: Original: 15.02.2024 | Result: 15.11.2023
ENR.
Remarks
If subtracting months results in an invalid day for the target month (e.g., subtracting 1 month from March 31st), the day is typically adjusted to the last valid day of that month (e.g., February 28th or 29th). This behavior is handled by the underlying date/time engine.
See also: