|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Operations |
MiniRobotLanguage (MRL)
DTO.ReformatDate Command
Reformat a date string using masks
Intention
This command converts a given date string from a specified source format into a new destination format. This is extremely useful for normalizing dates from different systems (e.g., converting a US-style date "MM/DD/YYYY" to an ISO-style date "YYYY-MM-DD").
The command works by using format "masks" to understand the structure of the input and output strings. The masks define the components of the date:
• YYYY: 4-digit year (e.g., 2025)
• YY: 2-digit year (e.g., 25). Assumed to be in the 21st century (20xx).
• MM: 2-digit month (01-12)
• M: 1 or 2-digit month (1-12)
• DD: 2-digit day (01-31)
• D: 1 or 2-digit day (1-31)
The separator character (e.g., ., /, -) is detected automatically from the format string.
Syntax
DTO.refd|SourceFMT|DestFMT|DateString[|$$ResultVar]
DTO.reformatdate|SourceFMT|DestFMT|DateString[|$$ResultVar]
Parameter Explanation
P1 - SourceFormat
A string mask describing the format of P3 (DateString).
Example: "MM/DD/YYYY"
P2 - DestinationFormat
A string mask describing the desired output format.
Example: "DD.MM.YYYY"
P3 - DateString
The actual date string (or a variable) that you want to convert.
Example: "12/25/2025"
P4 - $$ResultVar (Optional)
The variable where the reformatted date string will be stored. If this parameter is omitted, the result is placed on TOS (Top of Stack).
Example
'**********************************************
' DTO.refd - Sample
'**********************************************
'
' --- Example 1: US (MM/DD/YYYY) to German (DD.MM.YYYY) ---
$$US_Date = "10/20/2025"
$$SrcFmt = "MM/DD/YYYY"
$$DstFmt = "DD.MM.YYYY"
DTO.refd|$$SrcFmt|$$DstFmt|$$US_Date|$$GER_Date
DBV.US to German: $$GER_Date ' Result: "20.10.2025"
'
' --- Example 2: German (DD.MM.YY) to ISO (YYYY-MM-DD) ---
' Note: 2-digit years (YY) are assumed to be 20xx
$$GER_ShortDate = "31.01.99"
$$SrcFmt = "DD.MM.YY"
$$DstFmt = "YYYY-MM-DD"
DTO.refd|$$SrcFmt|$$DstFmt|$$GER_ShortDate|$$ISO_Date
DBV.German (YY) to ISO: $$ISO_Date ' Result: "2099-01-31"
'
' --- Example 3: Using TOS (Top of Stack) ---
DTO.refd|"YYYY-MM-DD"|"MM/DD/YYYY"|"2024-07-31"
POP.$$TOS_Result
DBV.ISO to US (from TOS): $$TOS_Result ' Result: "07/31/2024"
'
' --- Example 4: Invalid date ---
$$InvalidDate = "32.13.2025"
DTO.refd|"DD.MM.YYYY"|"YYYY-MM-DD"|$$InvalidDate|$$Result
DBV.Invalid Date: $$Result ' Result: "" (empty string)
'
ENR.
Remarks
This command is effectively a combination of DTO.ParseDate and DTO.FormatDate.
If the DateString cannot be parsed using the SourceFormat (e.g., "31.02.2025" or "99/99/99"), the command will return an empty string.
When using 2-digit years (YY), the year is automatically prefixed with 20. For example, 25 becomes 2025.
Limitations
The command only reformats the string; it does not perform date calculations.
The parsing requires the SourceFormat to exactly match the structure of the DateString.
See also
• DTO.Reformat Time - reformat time using mask
• DTO.Parse Date - parse date into components
• DTO.Format Date - format date components to string
• DTO.Make Date Mask - create date format mask
• DTO.Date To English - convert date to US format
• DTO.Get Date Separator - detect date separator char