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 / [PAD] Subtract Dates i...
Power Automate
Answered

[PAD] Subtract Dates into a specific format

(1) ShareShare
ReportReport
Posted on by 4

Task: I'm looking for a simple way to subtract %EndDate% from %StartDate% and get the result in hh:mm:ss format. My current flow has 59 actions and I don't like it. Is there an easy way to get date/time difference between 2 dates in hh:mm:ss format? Thanks!

I have the same question (0)
  • Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @farb 

    What format should your start date and end date follow in this context?

    Will you be providing them as DD-MM-YYYY with HH:MM:SS, or only as the date without the time?

    Please clarify this.

     
  • CU05081807-0 Profile Picture
    4 on at

    Hi Deenuji, like this: dd.MM.yy hh:mm:ss

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @farb 

    Please follow the below approach(Simple .Net script):

    Deenuji_0-1709805429574.png

    Code(Copy and paste the below code into you flow designer workspace):

     

    SET StartDate TO $'''01.03.24 00:00:00'''
    SET Enddate TO $'''05.03.24 12:34:56'''
    SET Difference TO $'''%''%'''
    Scripting.RunDotNetScript Imports: $'''System''' Language: System.DotNetActionLanguageType.CSharp Script: $'''
    
    // Parse the input strings into DateTime objects
    DateTime startDate = DateTime.ParseExact(startDateString, \"dd.MM.yy HH:mm:ss\", System.Globalization.CultureInfo.InvariantCulture);
    DateTime endDate = DateTime.ParseExact(endDateString, \"dd.MM.yy HH:mm:ss\", System.Globalization.CultureInfo.InvariantCulture);
    
    // Calculate the time difference
    TimeSpan timeDifference = endDate - startDate;
    
    // Format the result in hh:mm:ss format
    result = String.Format(\"{0:D2}:{1:D2}:{2:D2}\", (int)timeDifference.TotalHours, timeDifference.Minutes, timeDifference.Seconds);
    ''' @'name:startDateString': StartDate @'type:startDateString': $'''String''' @'direction:startDateString': $'''In''' @'name:endDateString': Enddate @'type:endDateString': $'''String''' @'direction:endDateString': $'''In''' @'name:result': $'''''' @'type:result': $'''String''' @'direction:result': $'''Out''' @result=> Difference

     

     

    If my response addresses your concern, please consider marking it as the solution 🌟  and giving it a thumbs up 👍. This helps others in the future and also serves as motivation for me. Thank you!

     

  • CU05081807-0 Profile Picture
    4 on at

    Works like a charm, thank you! 🙂

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

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 246 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 176

#3
Haque Profile Picture

Haque 157

Last 30 days Overall leaderboard