Adrian Nier Code

Back to overview

Month from string

Last modification: Thursday, April 30, 2009 06:16 pm

Returns the AppleScript month constant for a string like "Jan", "January", "Oct", or "October."

Required parameters
Parameter 1 (string)
A three or more character string representing a month.

Function Call

monthFromString("Dec")

Implementation

on monthFromString(_string)
   
   set _shortMonthNames to {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
   set _longMonthNames to {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
   
   set _date to current date
   repeat with _monthNumber from 1 to 12
      
      set _shortName to item _monthNumber of _shortMonthNames
      set _longName to item _monthNumber of _longMonthNames
      
      if _string is _shortName or _string is _longName then
         set month of _date to _monthNumber
         return month of _date
      end if
      
   end repeat
   
   return false
   
end monthFromString