Do you want to know how to get the current year in Power Automate? Then, read this complete tutorial to understand how to display the current year in Power Automate by applying the FormatDateTime function.
We will do the following things:
- Get the current year in Power Automate.
- How to get the previous year in Power Automate?
- Get next year in Power Automate.
Recently, I worked on a project where a client required me to extract the current year, previous year, and next year in a Power Automate flow using the formatDateTime function.
According to the requirement, here, we must extract the current year, previous year, and next year using utcNow(), i.e.(14-10-2023).
For that, I will create an “Instant cloud flow” that will trigger manually in Power Automate.
Get Current Year in Power Automate
1. Navigate to https://make.powerautomate.com/ and click on + Create -> select “Instant cloud flow”. In the next window, provide a flow name, select “Manually trigger a flow”, and click on Create.
2. Then, add an “Initialized variable” to store the data and use it for any calculations or data management during the flow. Here, provide details below:
- Name: Set a name for an initialized variable.
- Type: Select datatype as ‘String‘ from the drop-down.
- Value: Add the below code in value.
3. Then, add a Compose data operation to check the output from an initialized variable.
4. Now, the flow is ready. Click on the Save button. Click on Test -> Manually to test flow.
5. Then, the outputs of the compose flow action will display the current year.
This is how to get the current year using the Power Automate flow.
Get Previous Year in Power Automate
Similarly, here, based on the current date (14-10-2023) in Power Automate, I will show you how to get the previous year inside a flow.
In Power Automate, getting the previous year involves using the utcNow() function to get date and time values in UTC and formatting the date value into a year as an integer.
Follow the below step-by-step instructions to create an instant cloud flow:
1. Select Power Automate under the App launcher. Click on +Create -> Select “Instant cloud flow”. In the next window, provide a flow name, choose “Manually trigger a flow” and click on Create.
2. Then, add an “Initialize variable” flow action for formatting date and time and provide details below:
- Name: Set a name for a variable.
- Type: Select datatype as ‘String’ from drop-down.
- Value: Provide the below expression in value.
3. Next, add a “Compose” data operation and select inputs as below.
- Inputs: Select output from variables under dynamic content.
4. The Output generated from the compose flow action shows the previous year.
This is how to get the previous year by the formatDateTime function in Power Automate flow.
Get Next Year in Power Automate
Now, I will explain how to get the next year in a Power Automate flow based on the utcNow() function.
For getting next year by using a Power Automate flow, similarly follow the same.
Here, I will follow the same step-by-step process to create a Power Automate flow, and will use this time formatDatetime() function in an initialized variable to get the current date with the year.
Then, I will use the add and int functions to convert the string year to a year integer value.
Follow the below instructions in an “Instant cloud flow”:
1. In the “Initialized variable”, provide the below expression in value with details below.
- Name: Provide a name for a variable.
- Type: Select datatype from the drop-down.
2. Then, add a “Compose” data operation and set the details below.
- Inputs: Select from the dynamic content of the initialized variable.
3. The outputs of a compose flow action will show next year inside a flow.
This is how to extract next year from the formatDateTime() function in a Power Automate flow.
I hope you got a clear view of how to get the current year from the utcNow() function in Power Automate. In addition to that, I have converted the year string to a year integer by the int() function.
You may also like:
- How to Get Current Date in Power Automate?
- How to Convert String to Integer in Power Automate?
- How to Get Current and Previous Month in Power Automate?
- How to Update SharePoint List Date and Time Column in Power Automate?
Preeti Sahu is an expert in Power Apps and has more than 6 years of experience working with SharePoint and the Power Platform. As a Power Platform expert for Power BI, Power Apps, Power Automate, Power Virtual Agents, and Power Pages, she is currently employed with TSinfo Technologies. She is the author of the book Microsoft Power Platform A Deep Dive. She also made a big technical contribution to SharePointDotNet.com in the form of articles on the Power Platform. She enjoys traveling and spending time with her family in her spare time.