# Calculating Month Number Based on Month Name

This topic is 5669 days old. Please don't post here. Open a new topic instead.

## Recommended Posts

Hello,

As I am trying to expand my experiance, I'm trying to make calculations harder on myself so I can learn. Here is what I did with finding the month number from a Month Name:

```

Let (

list =  ValueListItems ( Get ( FileName ) ; "Month List" );

ValueCount ( Left (list ; Position ( list ; Month::SelectMonth ; 1 ; 1 ) + Length ( Month::SelectMonth ) ) )

)```

SelectMonth Values:

January

Febraury

March

April

May

June

July

August

September

October

November

December

I didn't want to hardcode any months even though I could have used a simple Case function; what other ways are there to calculate a month number based on its name?

Thanks and God Bless!

David

##### Share on other sites

I can think of several, but when you say you don't want to hardcode, it begs the question of language. You yourself have hardcoded the ENGLISH month names into a value list. What if the user is French?

Another question is the input method: in English, the first 3 letters of the month name are enough to identify the month. So if you limit yourself to English, you could use the same formula for short or full month name as the input, for example:

Let ( [

string = "janfebmaraprmayjunjulaugsepoctnovdec" ;

mmm = Left ( Input ; 3 )

] ;

Ceiling ( Position ( string ; mmm ; 1 ; 1 ) / 3 )

)

It wouldn't be too hard to compile a list of 12 month names in the current language, but I don't know the minimum length required to identify the month in each languages.

##### Share on other sites

Hi

I know the you own FM8 and not the Advanced version, but isn't to difficult to ask someone to make a black file with this custom inside...

This custom function makes what you want and is *NOT* depending from the used language.

------------------------

/*

MonthNameToMonth custom function

Author: Daniele Raybaudi

Format: MonthNameToMonth ( theMonthName ; start )

Parameters:

theMonthName - text

start - number (must be set to 1)

Returns the month number of the given monthName

*/

Let([

date = Date ( start ; 1 ; 1 );

month = Month ( date )

];

Case(

start > 12 or IsEmpty ( theMonthName ) ; "?" ;

MonthName ( date ) = theMonthName ; month ;

MonthNameToMonth ( theMonthName ; start + 1 )

)

)

##### Share on other sites

for example, the attached file is for ITALIAN's and you can try it with italian monthNames:

gennaio = 1

febbraio = 2

....

For use with English monthNames, simply make a clone of the file ! :

blankFile.zip

##### Share on other sites

This topic is 5669 days old. Please don't post here. Open a new topic instead.

## Create an account

Register a new account