cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Convert Month text to number

Hi,

 

Is there any function to convert the month in text to number?

 

For example convert FEB to 02, Jan to 01 and so on.

 

Thanks,

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Dual Super User III
Dual Super User III

Re: Convert Month text to number

@adri3 

Good question. My answer is to use a workaround, but I will be happy if somebody else points to a funtion so I can use it in my own projects.

My suggested workaround is to build your own Array of Months:

Initialize variable

Name: MonthsArray

Type: Array

Value: [{Month: "JAN",Index: "01"},...,{Month: "DEC",Index: "12"}]

 

Now let's assume the month expression you want to translate is stored in a variable called 'currentInputMonth':

Filter Array

Input: variables('MonthsArray')

Filter equals(item()?['Month'],variables('currentInputMonth')

 

Now let's assume you want to store the result in a variable called 'currentOutputMonth'

Initialize variable

Name: currentOutputMonth

Type: string

Value: if(equals(length(body('Filter_array')),1),first(body('Filter_array'))?['Index'],'ERROR')

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

Highlighted
Super User II
Super User II

Re: Convert Month text to number

Hi @adri3 

 

Try the following:

 

formatDateTime('01-Feb-2010','MM')

 

You can insert the value that you want in the place of the "Feb" based on the field that you want. The day and year are irrelevant. It's just to get a valid date.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel 

View solution in original post

4 REPLIES 4
Highlighted
Dual Super User III
Dual Super User III

Re: Convert Month text to number

@adri3 

Good question. My answer is to use a workaround, but I will be happy if somebody else points to a funtion so I can use it in my own projects.

My suggested workaround is to build your own Array of Months:

Initialize variable

Name: MonthsArray

Type: Array

Value: [{Month: "JAN",Index: "01"},...,{Month: "DEC",Index: "12"}]

 

Now let's assume the month expression you want to translate is stored in a variable called 'currentInputMonth':

Filter Array

Input: variables('MonthsArray')

Filter equals(item()?['Month'],variables('currentInputMonth')

 

Now let's assume you want to store the result in a variable called 'currentOutputMonth'

Initialize variable

Name: currentOutputMonth

Type: string

Value: if(equals(length(body('Filter_array')),1),first(body('Filter_array'))?['Index'],'ERROR')

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

Highlighted
Super User II
Super User II

Re: Convert Month text to number

Hi @adri3 

 

Try the following:

 

formatDateTime('01-Feb-2010','MM')

 

You can insert the value that you want in the place of the "Feb" based on the field that you want. The day and year are irrelevant. It's just to get a valid date.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel 

View solution in original post

Highlighted
Frequent Visitor

Re: Convert Month text to number

Brilliant. Thank you. Just what I was looking for

Highlighted
Dual Super User III
Dual Super User III

Re: Convert Month text to number

@manuelstgomes Much more elegant than mine. Thanx for sharing!



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Helpful resources

Announcements
Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Upcoming Events

Experience what’s next for Power Automate

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Top Solution Authors
Users online (7,721)