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.AddToCurrentTime - Add Hours to Current Time

Previous Top Next


MiniRobotLanguage (MRL)

 

DTO.AddToCurrentTime Command

Add a Specific Number of Hours to the Current System Time

 

Intention

 

The DTO.AddToCurrentTime command provides a convenient shortcut to calculate a future time relative to the exact moment the command is executed. It fetches the current system time, adds a specified number of hours, and returns the resulting time.

 

This is particularly useful for setting short-term deadlines, calculating expiration times, or scheduling tasks that need to occur a few hours from "now". The command correctly handles time rollovers past midnight.

 

Syntax

 

DTO.AddToCurrentTime|hours|[format]|[$$RES]

 

Parameter Explanation

 

hours - The number of hours to add to the current time. This must be a numeric value. Use a negative number to subtract hours.

 

format - (Optional) A string that specifies the output format of the resulting time (e.g., "HH:MM", "hh:nn:ss.ttt"). If omitted, the default format is "HH:MM:SS".

 

$$RES - (Optional) The variable to store the calculated time string.

 

Example

 

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

' DTO.AddToCurrentTime - Sample

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

'

' Get the current time for reference.

DTO.GetCurrentTime||$$NOW

'

' Calculate the time 3 hours from now.

DTO.AddToCurrentTime|3||$$FUT

MBX.Current time is $$NOW. In 3 hours it will be $$FUT.

'

' Calculate the time 2 hours ago using a negative number and a custom format.

$$FMT = "HH:MM"

DTO.AddToCurrentTime|-2|$$FMT|$$PAS

MBX.Two hours ago, the time was approximately $$PAS.

ENR.

 

Remarks

 

The calculation is performed on the system time at the exact moment the command is executed. If you need to add hours to a specific, static time, use the DTO.AddHours command instead.

 

Limitations:

 

The `hours` parameter must be a valid integer. The command does not support adding fractional hours.

 

See also:

 

    DTO. - Date Time Operations

    DTO.Add To Current Date

    DTO.Add Hours

    DTO.Get Current Time

    DTC. - Date and Time Calculation