Date & Time Calculations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Date and Time Calculation > DTO. - Date Time Operations >

Date & Time Calculations

DTO.SubtractDays - Subtract Days from a Date

Previous Top Next


MiniRobotLanguage (MRL)

 

DTO.SubtractDays Command

Subtract a Number of Days from a Specific Date

 

Intention

 

The DTO.SubtractDays command calculates a past date by subtracting a specified number of days from a starting date. It correctly handles rolling back across month and year boundaries.

 

This is useful for finding the start date of a period (e.g., "90 days before an expiration date"), calculating a date in the past for logging or reporting, or determining a deadline based on an event. The command is the direct counterpart to DTO.AddDays.

 

Syntax

 

DTO.SubtractDays|date|days|[format]|[$$RES]

 

Parameter Explanation

 

date - The starting date string from which days will be subtracted.

 

days - The number of days to subtract. This should be a positive integer.

 

format - (Optional) A format mask for the input `date` string and the output result. If omitted, "DD.MM.YYYY" is assumed.

 

$$RES - (Optional) The variable to store the resulting date string.

 

Example

 

'**********************************************

' DTO.SubtractDays - Sample

'**********************************************

'

' --- Sample 1: Find the date 10 days before March 5, 2024 ---

$$DAA = "05.03.2024"

DTO.SubtractDays|$$DAA|10|$$RES

MBX.10 days before $$DAA was $$RES ' Result: 24.02.2024

'

' --- Sample 2: Find the date 365 days ago from a specific date ---

$$DAB = "2025/01/15"

$$FMT = "YYYY/MM/DD"

DTO.SubtractDays|$$DAB|365|$$FMT|$$RES

MBX.One year before $$DAB was $$RES ' Result: 2024/01/15

ENR.

 

Remarks

 

The `days` parameter should always be a positive number representing the quantity to subtract. To add days, use the DTO.AddDays command.

 

Limitations:

 

The command requires a valid start date. Providing an invalid date string will cause an error.

 

See also:

 

    DTO. - Date Time Operations

    DTO.Add Days

    DTO.Date Diff

    DTO.Add To Current Date

    DTC. - Date and Time Calculation