web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Getting years between ...
Power Automate
Answered

Getting years between two dates

(0) ShareShare
ReportReport
Posted on by 3,295

Hello community.

 

Sorry silly question here:

 

I need to get the number of years between the hire date and Today's date and the result should be in a single value. So no decimals. i.e. Seniority Employee A = 23 Years

 

sajarac_0-1612354983634.png

 

BTW, The hire date value will be read from my data source "excel", and today's I am declaring the value in my flow via utcnow

 

Could someone point me in the right direction?

 

thanks in advance,

 

Regards

Categories:
  • Verified answer
    jinivthakkar Profile Picture
    4,187 on at

    @sajarac 

     

    jinivthakkar_0-1612359343837.png

     

    jinivthakkar_1-1612359429015.png

     

    jinivthakkar_2-1612359474262.png

    what i did - I took random dates, extracted the year part and did subtraction

     

    jinivthakkar_3-1612359557972.png

    jinivthakkar_4-1612359606083.png

     

    jinivthakkar_5-1612359638888.png

     

    Additionally, check this out which will help you in reading excel data and I already showed you how to get the difference in dates.

     

    https://www.youtube.com/watch?v=F2leKcMPAtw&t=127s

     

     

    --------------------------------------------------------------------------------
    If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

     

     

     

     

     

     

     

     

  • jinivthakkar Profile Picture
    4,187 on at

    @sajarac all of this can be achieved using one flow which reads excel row by row and gives you the difference. If you don't know just check out the link I gave or you will a lot of content on how to read excel using power automate.

    Hope this helps.

     

    --------------------------------------------------------------------------------
    If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

     

  • Sajarac Profile Picture
    3,295 on at

    Thank you very much for your prompt response, I was totally lost. I was thinking that the compose function will be a single formula with a subtraction or something similar. Thanks again I will implement your solution.

  • Hardesh15 Profile Picture
    7,087 Super User 2024 Season 1 on at

    @sajarac Addition to @jinivthakkar solution.

    If you want to minimize actions- you can use 'yyyy' in each date expression. it will give you only years. Example-Formatdatetime(utcnow(),'yyyy')==> 2021

    adddays(utcnow(),2000,'yyyy)==>2026

     

    Please 'Thumbs Up' the posts that helped you and 'Mark as Solution' if my post answered your question.

    @Hardesh

  • Sajarac Profile Picture
    3,295 on at

    Hi, sorry to bother you I have a couple of questions?

     

    1. In my data source Y have the hire date in this format MM/dd/yyyy. And in your flow you have set as 'yyyy-MM-dd'. Can I change all the format or it affects the flow?

     

    2. In the Initialize Variable 2, what does it means the number 2000?

     

    3. In the Compose what does it means the "0,4" numbers?

     

    Sorry silly questions but I would like to understand the formula applied.

     

    Thanks in advance

  • Hardesh15 Profile Picture
    7,087 Super User 2024 Season 1 on at

    @sajarac  1. You can use any format. It does not impact your flow.

    2. 2000 are number of days added in current time.

    3. It is start and end index number of a string.

    Please 'Thumbs Up' the posts that helped you and 'Mark as Solution' if my post answered your question.

    @Hardesh

  • theresan Profile Picture
    4 on at

    I realize this post is 10 months old but was hoping for some help. When I implement your instructions, it always returns 6 years. I don't understand why you are adding 2000 days.

  • Hardesh15 Profile Picture
    7,087 Super User 2024 Season 1 on at

    @theresan This was expression to explain requirement. you can add number of days in current days as per your requirement.

    adddays(utcnow(),2000,'yyyy) => you can change it to 365  and you will see next year as output. if i change this expression adddays(utcnow(),365,'yyyy-MM-dd') then you will find next year date.

    hope it clears your doubt.

    Please 'Thumbs Up' the posts that helped you and 'Accept as Solution' if my post answered your question.

    @Hardesh /Gopenly.in

     

  • theresan Profile Picture
    4 on at

    Sorry for my confusion but I am just not getting this. I have a spreadsheet which I use Get Items to access. I want to compare a date in that spreadsheet to today. It always says 6 years which I understand now that it is because you are adding 2000 days to todays date but the varHireDate variable you created needs to be my actual hire date. I can't figure out how to pull in my hire date as initialize variable in order to compare it. 

  • gatorgirl1298 Profile Picture
    6 on at

    The example and solution provided are backwards for what I am looking to use this for.  I want to take the date today in yyyy and subtract the Hire Date in yyyy.  So the add days 2000 makes no sense to me.  I have two dates that are static, and I need to find the difference between the dates.  What am I missing?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 414

#2
11manish Profile Picture

11manish 335 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard