|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Calculations |
MiniRobotLanguage (MRL)
DTO.SubtractHours Command
Subtract a Number of Hours from a Time
Intention
The DTO.SubtractHours command calculates a new time by subtracting a specified number of hours from a given time string. It correctly handles "time rollovers," where subtracting hours crosses midnight into the previous day.
This is useful for calculating start times based on an end time and duration, converting time zones, or scheduling events that need to occur a certain number of hours before a deadline. The command simplifies time arithmetic by managing the complexities of 24-hour time cycles automatically.
Syntax
DTO.SubtractHours|time|hours|[format]|[$$RES]
Parameter Explanation
time - The source time string from which hours will be subtracted (e.g., "14:00:00").
hours - The number of hours to subtract. This should be a positive integer.
format - (Optional) The format of the `time` string and the desired output format. Defaults to "HH:MM:SS" if omitted.
$$RES - (Optional) The variable to receive the resulting time string.
Example
'**********************************************
' DTO.SubtractHours - Sample
'**********************************************
'
' --- Sample 1: Subtract 4 hours from an afternoon time ---
$$TMA = "15:30:00"
DTO.SubtractHours|$$TMA|4|$$RES
MBX.15:30 minus 4 hours is: $$RES ' Result: 11:30:00
'
' --- Sample 2: Subtract hours crossing midnight ---
$$TMB = "02:15:00"
DTO.SubtractHours|$$TMB|5|$$RES
MBX.02:15 minus 5 hours is: $$RES ' Result: 21:15:00
'
' --- Sample 3: Using a custom time format ---
$$TMC = "01.00"
DTO.SubtractHours|$$TMC|2|HH.MM|$$RES
MBX.01.00 minus 2 hours is: $$RES ' Result: 23.00
ENR.
Remarks
The command returns only the resulting time. It does not provide information about the date, even if the calculation crosses a day boundary.
Limitations:
Requires a valid time string in the specified (or default) format. Malformed time strings will cause a parameter error.
See also:
• DTC. - Date and Time Calculation