|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Calculations |
MiniRobotLanguage (MRL)
DTO.AddDays Command
Add or Subtract Days from a Specific Date
Intention
The DTO.AddDays command performs date arithmetic by adding or subtracting a specified number of days from a given date. This is a fundamental operation for calculating future or past dates, such as project deadlines, follow-up reminders, expiration dates, or start dates for reports.
The command intelligently handles all date complexities, such as rolling over to the next month or year, and correctly accounts for the number of days in each month, including leap years. By providing a negative number, you can easily calculate a date in the past. It differs from DTO.AddToCurrentDate by operating on any specified date, not just today's date.
Syntax
DTO.AddDays|date|days|[format]|[$$RES]
Parameter Explanation
date - The starting date string. Can be a variable (e.g., $$DAA) or a literal value (e.g., "25.12.2024").
days - The number of days to add. Use a positive integer to calculate a future date or a negative integer to calculate a past date.
format - (Optional) The format mask for both the input `date` string and the resulting output string. If omitted, "DD.MM.YYYY" is assumed.
$$RES - (Optional) The variable to store the newly calculated date string.
Example
'**********************************************
' DTO.AddDays - Sample
'**********************************************
'
' --- Sample 1: Add 10 days to a date ---
$$DAA = "15.03.2024"
DTO.AddDays|$$DAA|10||$$RES
MBX.10 days after $$DAA is $$RES. ' Result: "25.03.2024"
'
' --- Sample 2: Subtract 20 days, crossing a month boundary ---
$$DAB = "10.04.2024"
DTO.AddDays|$$DAB|-20||$$RES
MBX.20 days before $$DAB was $$RES. ' Result: "21.03.2024"
'
' --- Sample 3: Add days over a leap day using a custom format ---
$$DAC = "2024/02/25"
$$FMT = "YYYY/MM/DD"
DTO.AddDays|$$DAC|5|$$FMT|$$RES
MBX.5 days after $$DAC is $$RES. ' Result: "2024/03/01"
ENR.
Remarks
This command is the direct counterpart to DTO.SubtractDays. Using DTO.AddDays with a negative value is equivalent to using DTO.SubtractDays with a positive value.
Limitations:
The command requires a valid date string as input. An invalid date will result in a parameter error.
See also: