Date & Time Calculations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Date and Time Calculation > DTO. - Date Time Operations >

Date & Time Calculations

DTO.GetDaysInMonth - Get Number of Days in a Month

Previous Top Next


MiniRobotLanguage (MRL)

 

DTO.GetDaysInMonth Command

Get Number of Days in a Month

 

Intention

 

The DTO.GetDaysInMonth command is a powerful utility for accurately determining the number of days in a specific month of a given year. It intelligently handles the complexities of the calendar, most notably the varying length of February in leap years.

 

Instead of manually coding logic to check for months with 30 or 31 days, or implementing the leap year algorithm for February, this command provides a direct and reliable answer. This is essential for tasks such as:

Validating user-entered dates (e.g., preventing an entry like "31.04.2024").
Setting up loops that need to iterate through every day of a particular month.
Calculating end-of-month dates for reports or financial processes.

 

Syntax

 

DTO.GetDaysInMonth|date|[format]|[$$RES]

 

Parameter Explanation

 

date - The date string whose month and year will be evaluated. The specific day in the string does not affect the outcome.

 

format - (Optional) The format mask of the `date` string (e.g., "MM-DD-YYYY"). If omitted, the standard "DD.MM.YYYY" format is used.

 

$$RES - (Optional) The variable where the numeric result (28, 29, 30, or 31) will be stored.

 

Example

 

'**********************************************

' DTO.GetDaysInMonth - Sample

'**********************************************

'

' --- Sample 1: Check February in a leap year (2024) ---

$$DAA = "10.02.2024"

DTO.GetDaysInMonth|$$DAA||$$RES

MBX.February 2024 has $$RES days. (Expected: 29)

'

' --- Sample 2: Check February in a non-leap year (2023) ---

$$DAB = "05.02.2023"

DTO.GetDaysInMonth|$$DAB||$$RES

MBX.February 2023 has $$RES days. (Expected: 28)

'

' --- Sample 3: Check a 30-day month (September) using a custom format ---

$$DAC = "2025-09-20"

$$FMT = "YYYY-MM-DD"

DTO.GetDaysInMonth|$$DAC|$$FMT|$$RES

MBX.September 2025 has $$RES days. (Expected: 30)

ENR.

 

Remarks

 

Only the month and year components of the input `date` are used for the calculation. The day component is ignored.

 

Limitations:

 

The command requires a valid date string that can be parsed. Providing an invalid month (e.g., "15.13.2024") will result in an error.

 

See also:

 

    DTO. - Date Time Operations

    DTO.Is Leap Year

    DTO.Get Current Date

    DTO.Add Months

    DAT. - Date and Time Information (System independent)