Do you need to get the full month name based on a date in your flow?
Often dates created and used by systems are not as user-friendly as those that use the full month name.
You may encounter scenarios where you need to retrieve the full month name from a date.
This can be achieved with either the Convert time zone action or the formatDateTime function. Both these will allow you to format any date as the month only.
This post will show you how to use both methods to extract the full month name from any date in your flow.
Get the Month Name with the Convert Time Zone Action
Power Automate doesn’t have a specific action for formatting dates, but you can use an action meant for converting timezones to accomplish your formatting.
The Convert time zone action let’s you convert a date and timestamp from one timezone to another, but it has additional functionality that allows you to format the result.
You can convert the timezone from UTC to UTC, therefore not changing the time, then use the formatting options as needed.
Here’s how to use the Convert time zone action to format your date as the full month name.
- Add the Convert time zone action to your flow.
- Add the date for which you want to get the month name into the Base time field.
- Select UTC as the Source time zone.
- Select UTC as the Destination time zone. You can select any time zone for the source and destination as long as you select the same for both. This way, you won’t change the date and timestamp you are formating.
- Click on the dropdown list for the Format string, and select the Enter custom value option. This will allow you to enter your own custom format string.
- Enter the Format string as
MMMM
. This format string will return the full month name. For example, a date of 2023-09-12 will return the value September.
💡 Tip: You can also use the format string MMM
to return the 3-character abbreviated month name. For example, a date of 2023-09-12 will return the value Sep.
The action should now output the month name in a more readable format.
Get the Month Name with the formatDateTime Function
The formatDateTime function can be a more convenient method for getting the month name since it can be used directly within any action input in your flow.
This function enables you to transform a date value into various formats, including the full month name.
You need to define the date for which you want to extract the month name. You can use the current date by using the utcNow()
function or provide your own date value.
Once you have a date, apply the formatDateTime function on the date and use the 'MMMM'
format specifier to obtain the full month name.
formatDateTime(utcNow(),'MMMM')
The above sample expression will get the full month name from the current date.
formatDateTime(outputs('Compose'), 'MMMM')
If you have a specific date value, you can adjust the expression with your own date value as shown above. This expression will get the full month name from a date in the Compose action.
For example, if the flow runs on 2023-09-12, this expression will return the full month name September. This allows you to easily extract the desired month name from any date value.
Conclusions
Converting a date to its full month name can be easily achieved using either the Convert time zone action or the formatDateTime function.
With either of these methods, you can use the custom format string MMMM
to get the full month name from your date.
Have you needed the month name from a date in your flow? How did you get this? Let me know in the comments below!
0 Comments