|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Calculations |
MiniRobotLanguage (MRL)
DTO.GetDayOfWeek Command
Get Day of the Week as a Number (1-7)
Intention
The DTO.GetDayOfWeek command provides a simple and reliable method to determine the specific day of the week for any given date. It returns a number from 1 to 7, which corresponds to a specific day.
Numeric Mapping:
The command uses the following standard mapping:
1 = Sunday
2 = Monday
3 = Tuesday
4 = Wednesday
5 = Thursday
6 = Friday
7 = Saturday
This functionality is extremely useful for scheduling tasks, automating reports, or any logic that needs to differentiate between weekdays and weekends.
Syntax
DTO.GetDayOfWeek|date|[format]|[$$RES]
Parameter Explanation
date - The date string to be evaluated. This can be a variable or a literal string.
format - (Optional) A string that specifies the format of the `date` parameter (e.g., "MM/DD/YYYY"). If omitted, the default format "DD.MM.YYYY" is assumed.
$$RES - (Optional) The variable that will receive the numeric day of the week (1-7).
Example
'**********************************************
' DTO.GetDayOfWeek - Sample
'**********************************************
'
' Check the day of week for a known Friday.
$$DAA = "24.05.2024"
DTO.GetDayOfWeek|$$DAA||$$RES
MBX.The day of the week for $$DAA is $$RES. (Expected: 6)
'
' Use the result to determine if it is a weekend or weekday.
SCS.$$RES
CAN.1
MBX.$$DAA is a Sunday (Weekend).
CAN.7
MBX.$$DAA is a Saturday (Weekend).
CAE.
MBX.$$DAA is a weekday.
ESL.
ENR.
Remarks
Remember that the week starts with Sunday as 1. This might differ from other systems or programming languages where Monday is considered the first day of the week.
Limitations:
The command requires a valid and parsable date string. An invalid date, such as "32.01.2024", will cause a parameter error.
See also:
• DAT. - Date and Time Information (System independent)