|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Operations |
MiniRobotLanguage (MRL)
DTO.ghou Command
Get the numeric hour value from a time string
Intention
This command parses a time string, based on an optional format mask, and extracts the numeric value of the Hour component (0-23).
It uses the same underlying parsing logic as DTO.ParseTime but returns only the hour value.
Syntax
DTO.ghou|TimeString|[FormatMask]|[$$RES]
DTO.gethour|...
Parameter Explanation
P1 - TimeString (Required)
The time string (or a variable, e.g., $$TIM) containing the time value.
Example: "14:30:45"
P2 - FormatMask (Optional)
The format mask string (or variable, e.g., $$MSK) describing the structure of P1.
Example: "HH:MM:SS". If omitted, a default mask (like "HH:MM:SS" potentially including milliseconds, using ':' separator) is assumed.
P3 - $$RES (Optional)
The variable (e.g., $$RES) where the numeric hour value (0-23) will be stored. If omitted, the result is placed on TOS.
Example
'**********************************************
' DTO.ghou - Sample
'**********************************************
'
' --- Example 1: Get hour (default mask) ---
$$TIM = "14:30:45"
DTO.ghou|$$TIM||$$HOU
DBV.Hour 1: $$HOU ' Result: 14
'
' --- Example 2: Get hour with specific mask (dot separator) ---
$$TIM = "09.15.10"
$$MSK = "HH.MM.SS"
DTO.ghou|$$TIM|$$MSK|$$HOU
DBV.Hour 2: $$HOU ' Result: 9
'
' --- Example 3: Invalid time string ---
$$TIM = "NotATime"
DTO.ghou|$$TIM||$$HOU
DBV.Hour 3: $$HOU ' Result: 0 (Parsing failed)
'
ENR.
Remarks
This command provides a convenient way to get just the hour component without needing to parse all components using DTO.ParseTime.
If the parsing fails (invalid time string or mismatched mask), the command returns 0.
Limitations
- Relies on the accuracy of the provided FormatMask (or the default) matching the TimeString.
- Returns 0 if parsing fails, which could be ambiguous if the actual hour is 00.
See also
• DTO.Get Time Milliseconds (gtms)