days_in_month Function

public pure function days_in_month(month, year) result(d)

Return the number of days in a given month.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: month
integer, intent(in) :: year

Return Value integer


Source Code

    pure function days_in_month(month, year) result(d)
        !! version: experimental
        !!
        !! Return the number of days in a given month.
        integer, intent(in) :: month, year
        integer :: d
        integer, parameter :: mdays(12) = &
            [31,28,31,30,31,30,31,31,30,31,30,31]
        if (month < 1 .or. month > 12) then
            d = 0
            return
        end if
        d = mdays(month)
        if (month == 2 .and. is_leap_year_int(year)) &
            d = 29
    end function days_in_month