Skip to main content

Notifications

Power Automate - Building Flows
Unanswered

Expression to return interval between dates

Posted on 4 Dec 2024 09:07:43 by 380
Hi,
I could need som help with an expression.
I need to get the difference between two dates: today and a random date. I get the random date from a Get sharepoint items action (column 'Startdatum').
 
I have tried
int(split(dateDifference(utcNow(),item()?['Startdatum']),'.')[0])
and that works fine if the Startdatum is in the past. But if it is today or a future date, it fails.
 
I need an expression that works for past, current and future dates - that is, an expression that can return any negative number, any positive number, and 0.
 
  • Expiscornovus Profile Picture
    Expiscornovus 30,634 on 04 Dec 2024 at 11:20:27
    Expression to return interval between dates
     
    My bad, I didn't have my coffee yet. I totally misread your expression 😅☕
     
    In that case try the below:
    if(equals(first(dateDifference(utcNow(), item()?['StartDatum'])), '0'), 0, int(first(split(dateDifference(utcNow(), item()?['StartDatum']), '.'))))
     
  • MM-05080756-0 Profile Picture
    MM-05080756-0 380 on 04 Dec 2024 at 10:06:00
    Expression to return interval between dates
    Thank you @Expiscornovus,
    but that is almost exactly what I have tried.
    int(split(dateDifference(utcNow(),item()?['Startdatum']),'.')[0])
    The int and split is just to clean the result and only get the number of days (since dateDifference(utcNow(),item()?['Startdatum']) will also generate hours, minutes and seconds)
     
    If I follow your advice, it actually does work for past, current and future days. But I need the end result to be only the number of days. How do I convert for instance "-2.10:03:13.5724692" or "13:57:53.8184737" to number of days relative to today?
  • Expiscornovus Profile Picture
    Expiscornovus 30,634 on 04 Dec 2024 at 09:27:56
    Expression to return interval between dates
     
    If you want to calculate the difference between two dates you can use the datedifference function.
     
    Try the below instead:
    dateDifference(utcNow(), item()?['StartDatum'])
     

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,372

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,900

Leaderboard