|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Operations |
MiniRobotLanguage (MRL)
DTO.gyea Command
Get the numeric year value from a date string
Intention
This command parses a date string, based on an optional format mask, and extracts the numeric value of the **Year** component.
It correctly handles 2-digit years (YY) by assuming they belong to the 21st century (e.g., '25' becomes 2025).
Syntax
DTO.gyea|DateString|[FormatMask]|[$$RES]
DTO.getyear|...
Parameter Explanation
P1 - DateString (Required)
The date string (or a variable, e.g., $$DAT) containing the date value.
Example: "25.12.2025"
P2 - FormatMask (Optional)
The format mask string (or variable) describing the structure of P1.
Example: "DD.MM.YYYY". If omitted, a default mask ("DD.MM.YYYY" with '.' separator) is assumed.
P3 - $$RES (Optional)
The variable (e.g., $$RES) where the numeric year value will be stored. If omitted, the result is placed on TOS.
Example
'**********************************************
' DTO.gyea - Sample
'**********************************************
'
' --- Example 1: Get year from DD.MM.YYYY ---
$$DAT = "25.12.2025"
DTO.gyea|$$DAT||$$YER
DBV.Year 1: $$YER ' Result: 2025
'
' --- Example 2: Get year from MM/DD/YY ---
$$DAT = "04/15/24"
$$MSK = "MM/DD/YY"
DTO.gyea|$$DAT|$$MSK|$$YER
DBV.Year 2: $$YER ' Result: 2024
'
' --- Example 3: Get year from YYYY-MM-DD to TOS ---
$$DAT = "2026-03-01"
$$MSK = "YYYY-MM-DD"
DTO.gyea|$$DAT|$$MSK
POP.$$TOS
DBV.Year 3 (TOS): $$TOS ' Result: 2026
'
ENR.
Remarks
This command relies on the INT_ParseDateComponents backend function.
If the FormatMask is omitted, it defaults to a standard "DD.MM.YYYY" format.
Consider using the more comprehensive DTO.ParseDate (pdate) command if you need to extract multiple components simultaneously.
Limitations
- If the date string cannot be parsed correctly using the mask (e.g., "invalid date"), the result variable (or TOS) will contain 0.
See also