|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Calculations |
MiniRobotLanguage (MRL)
DTO.AddHours Command
Add or Subtract Hours from a Time
Intention
The DTO.AddHours command modifies a given time by adding a specified number of hours. It intelligently handles time rollovers, for example, adding 3 hours to `22:00` will correctly result in `01:00`. To subtract hours, simply provide a negative number.
This functionality is very useful for calculating future or past times, adjusting for time zones, or determining the end time of a process that has a known duration in hours.
Syntax
DTO.AddHours|time|hours|[format]|[$$RES]
Parameter Explanation
time - The initial time string (e.g., "14:30:00") that will be modified. Can be a variable or a literal.
hours - A numeric value for the hours to add. A negative value (e.g., -5) will subtract hours.
format - (Optional) The format for both the input `time` and the output result. If omitted, "HH:MM:SS" is used as the default.
$$RES - (Optional) The variable where the resulting time string is stored.
Example
'**********************************************
' DTO.AddHours - Sample
'**********************************************
'
' --- Sample 1: Add hours, crossing midnight ---
$$TAA = "22:45:10"
' Add 4 hours to the time in $$TAA.
DTO.AddHours|$$TAA|4||$$RES
MBX.22:45:10 + 4 hours is $$RES ' Result: 02:45:10
'
' --- Sample 2: Subtract hours, crossing midnight ---
$$TAB = "01:30:00"
' Subtract 3 hours from the time in $$TAB by adding a negative value.
DTO.AddHours|$$TAB|-3||$$RES
MBX.01:30:00 - 3 hours is $$RES ' Result: 22:30:00
'
' --- Sample 3: Using a custom separator ---
$$TAC = "14-15-00"
$$FMT = "HH-MM-SS"
' Add 2 hours, using a hyphen as a separator for input and output.
DTO.AddHours|$$TAC|2|$$FMT|$$RES
MBX.14-15-00 + 2 hours is $$RES ' Result: 16-15-00
ENR.
Remarks
This command correctly handles calculations that cross midnight. For instance, adding 2 hours to `23:00` will correctly yield `01:00`. While the calculation might logically cross into a new day, the command only returns the resulting time part.
Limitations:
The input time string must be valid and must match the provided format mask (or the default format if none is provided).
See also:
• DTC. - Date and Time Calculation