How can I check if leap year in AppleScript? The following code is to check if it's a leap year once the program detects the current month is February.

The "if" code seems quite redundant.

set MM to month of (current date) as number
if (MM = 2) then

    set YY to year of (current date)
    if (YY mod 400 = 0) then
        set Prefix to Gregorian_Leap
    else if (YY mod 100 = 0) then
        set Prefix to Gregorian_28
    else if (YY mod 4 = 0) then
        set Prefix to Gregorian_Leap
    else
        set Prefix to Gregorian_28
    end if

else if (MM = 4 or MM = 6 or MM = 9 or MM = 11) then
    set Prefix to Gregorian_30
else
    set Prefix to Gregorian_31
end if
An alternative approach would be to ask for the month of February 29. In a non-leap year, it should return 'March'.

month of date "2/29/2018"


This shows the approach but as pointed out in the comments, the above is automatically compiled into a long date.

To address this and to also provide flexibility as to the year, this will return ‘February’ in a leap year, and ‘March’ otherwise.

month of date ("2/29/" &amp; (year of (current date) as text))


-> March

Incorporating the question code, it could look like this. I ordered it this way so as to bail out of the elses earlier for more months.

set g31 to {1, 3, 5, 7, 8, 10, 12}
set g30 to {4, 6, 9, 11}

set MM to month of (current date) as integer

if g31 contains MM then
    set Prefix to "Gregorian_31"
else
    if g30 contains MM then
        set Prefix to "Gregorian_30"
    else
        if month of date ("2/29/" &amp; (year of (current date))) as integer = 2 then
            set Prefix to "Gregorian_Leap"
        else
            set Prefix to "Gregorian_28"
        end if
    end if
end if