|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Operations |
MiniRobotLanguage (MRL)
DTO.GetWeekNumber Command
Get the Week Number of a Date
Intention
This command calculates the week number (from 1 to 53) for a given date. It is useful for scheduling tasks, generating weekly reports, or grouping data by week.
Important: The command uses a simplified calculation and provides an approximation of the week number. It may not match the official ISO 8601 week number for dates near the beginning or end of the year. See the Remarks and Limitations sections for more details.
Syntax
DTO.getweeknumber|date|[format]|[$$ResultVar]
DTO.wnum|date|[format]|[$$ResultVar]
Parameter Explanation
P1 - date
The date string (or a variable) for which to calculate the week number.
P2 - format (Optional)
A string mask describing the format of P1. If omitted, the default format "DD.MM.YYYY" is assumed.
P3 - $$ResultVar (Optional)
The variable where the calculated week number (1-53) will be stored. If omitted, the result is placed on TOS.
Example
'**********************************************
' DTO.GetWeekNumber - Sample
'**********************************************
'
' --- Example 1: Calculate week number for a date in mid-year ---
$$DAA = "20.06.2024"
DTO.wnum|$$DAA||$$RES
DBV.Date $$DAA is approximately in week: $$RES
' Result: 25
'
' --- Example 2: Using a custom US date format ---
$$DAB = "12/25/2024"
$$FMT = "MM/DD/YYYY"
DTO.wnum|$$DAB|$$FMT|$$RES
DBV.Date $$DAB is approximately in week: $$RES
' Result: 51 (The actual ISO week is 52)
'
ENR.
Remarks
The internal function uses a simple algorithm that assumes every month has 30 days. This provides a fast but rough estimate of the week number.
Limitations
The calculation does not conform to the ISO 8601 standard for week dates. The ISO standard defines weeks as starting on a Monday, and the first week of the year is the one that contains the first Thursday. This command's calculation does not account for these rules and can be off by one or more weeks, especially for dates in January or December.
See also
• DTO.Get Day Of Week - get weekday number (1-7)
• DTO.Get Days In Month - get days in month
• DTO.Parse Date - parse date into components
• DAT. - Date and Time Information (System independent)