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.DateDiff - Calculate Days Between Dates

Previous Top Next


MiniRobotLanguage (MRL)

 

DTO.DateDiff Command

Calculate the Difference in Days Between Two Dates

 

Intention

 

The DTO.DateDiff command calculates the approximate number of days between two dates. It is a powerful tool for determining durations, calculating age, finding the number of days until a deadline, or measuring the time elapsed since an event.

 

The command subtracts the second date from the first (`date1` - `date2`). The result is a single integer: positive if the first date is later than the second, and negative if it is earlier.

 

Syntax

 

DTO.DateDiff|date1|date2|[format]|[$$RES]

 

Parameter Explanation

 

date1 - The first date string (minuend).

 

date2 - The second date string (subtrahend).

 

format - (Optional) The format mask for both `date1` and `date2`. If omitted, "DD.MM.YYYY" is assumed.

 

$$RES - (Optional) The variable where the resulting integer (number of days) will be stored.

 

Example

 

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

' DTO.DateDiff - Sample

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

'

' --- Sample 1: Calculate days between two dates ---

$$DAA = "31.12.2024"

$$DAB = "01.01.2024"

DTO.DateDiff|$$DAA|$$DAB||$$RES

MBX.Days between the two dates: $$RES

'

' --- Sample 2: Calculate age in days (using custom format) ---

$$TOD = "2024-05-21" ' Today's date

$$BRD = "1990-08-15" ' Birth date

DTO.DateDiff|$$TOD|$$BRD|YYYY-MM-DD|$$AGE

MBX.Approximate age in days: $$AGE

ENR.

 

Remarks

 

The result is positive if `date1` is chronologically after `date2`. The result is negative if `date1` is before `date2`.

 

Limitations:

 

Important: The internal calculation logic uses an approximation (Years * 365 + Months * 30 + Days). This means the result is generally accurate for estimations but may have a small margin of error over long periods or across many leap years. It is not recommended for high-precision financial or legal calculations where exact day counts are critical.

 

See also:

 

    DTO. - Date Time Operations

    DTO.Time Diff

    DTO.Add Days

    DTO.Is Date Passed

    DTC. - Date and Time Calculation