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 Apps / how to change input of...
Power Apps
Answered

how to change input of time to 24 hours format and duration calculation

(0) ShareShare
ReportReport
Posted on by 1,994

 

Hi I like to check I am using start time and end time as single text box, may I know how the formula to change it to 24hours format when user input eg 9am , 4pm etc and how to calculate the duration 

or is there a better field to use for the start and end time input, I don't want drop down selection of time.  Thank you

bbsin_0-1694091458242.png

 

Categories:
I have the same question (0)
  • Verified answer
    SpongYe Profile Picture
    5,909 Super User 2026 Season 2 on at

    Hi @bbsin 

     

    I made a simple example about you case:

    SpongYe_0-1694096118008.png

     

    In the TextInput.Default add the following code:

    00:00:00

     

    Set the OnChange property of the Text Input box (TextInput1) to following:

    TextInput1.OnChange
    
    If(
     IsMatch(TextInput1.Text, "\d{2}\:\d{2}:\d{2}"),
     true ,
     Notify("The time format you typed is not valid, the correct format should be (HH:MM:SS) 09:00:00 or 16:00:00",NotificationType.Error);Reset(TextInput1)
    )
    
    TextInput1_1.OnChange
    
    If(
     IsMatch(TextInput1_1.Text, "\d{2}\:\d{2}:\d{2}"),
     true ,
     Notify("The time format you typed is not valid, the correct format should be (HH:MM:SS) 09:00:00 or 16:00:00",NotificationType.Error);Reset(TextInput1_1)
    )

    Note: You should type xx:xx:xx string value within the Text Input box.

    The (:) should not be missed when you type the string value.

    More details about the IsMatch function, please check the following article:

    IsMatch function

     

    Then to calculate the duration put this on a label:

    DateDiff(TimeValue(TextInput1.Text), TimeValue(TextInput1_1.Text), TimeUnit.Minutes ) & " minute(s)"

     

    I hope this helps you.


    ------------------------------------------------------------------------------------------------------------------------------
    If I have answered your question, please mark your post as Solved. Remember, you can accept more than one post as a solution.

    If you like my response, please give it a Thumbs Up.

  • bbsin Profile Picture
    1,994 on at

    @SpongYe 

    thank you for your help
    when I put in the default, it show error, did I do it wrongly? Thanks

    bbsin_1-1694148412846.png

     

     

  • SpongYe Profile Picture
    5,909 Super User 2026 Season 2 on at

    You need to add the double quotes.

     

    "00:00:00"

  • bbsin Profile Picture
    1,994 on at

    @SpongYe great this works 


    Check  how to enable user to just input the time as 0700 /15:00
    or 7am  or 3pmas now they need to put in 07:00 as text to shoudl the 07:00 format

     

    bbsin_0-1694229273315.png

     

    @SpongYe For duration
    its displaying as total minutes, can to change to 1.45hrs?

    bbsin_1-1694229424309.png

     


    Thanks

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 July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#2
11manish Profile Picture

11manish 203 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard