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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / auto format a text imp...
Power Apps
Answered

auto format a text imput as time format

(0) ShareShare
ReportReport
Posted on by 97

Hi guys:

 

Good day, I am looking to auto format a text imput label where when the user write an hour it change auto:

 

User write --> 1910
Auto format --> 19:10

 

as you can see I want to avoid to the user write the colon.

 

Is any way to do that?

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    Hi @felipito1 ,

    This will work after the user presses Enter after 4 characters.

    Put this on the OnChange of the Text control (call the Variable whatever you like)

    If(
     Len(YourTextBoxName.Text) > 3,
     UpdateContext(
     {
     vColon: Left(
     TextInput1.Text,
     2
     ) & ":" & Right(
     TextInput1.Text,
     2
     )
     }
     );
     Reset(YourTextBoxName)
    )

    Make the Default of the Text box

    vColon

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • v-xida-msft Profile Picture
    on at

    Hi @felipito1 ,

    Do you want the Text Input value to be formatted as time automatically after you enter 4 number value?

     

    Based on the needs that you mentioned, I think the Timer control could achieve your needs. Please consider add a Timer control in your app screen. Set the Duration property to following:

    1000

    set the AutoStart and Repeat property to following:

    true

    set the OnTimerEnd property to following:

    If(
     Len(TextInput1.Text) = 4, // TextIput1 represents the Text Input box where enter your time value
     Set(
     FormattedResult,
     Left(TextInput1.Text, 2) & ":" & Right(TextInput1.Text, 2)
     )
    )

    Set the Visible property of the Timer control to false.

     

    Set the Default property of the TextInput1 to following:

    FormattedResult

    Please check the following GIF screenshot for more details:

    Test1.gif

    Note: The OnChange property of the Text Input could be fired only when the focus is move away from that Text Input box

     

    Best regards,

     

  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    Thank You @v-xida-msft for the alternative.

    @felipito1 you might try mine as well if you want something less complex

  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    Hi @felipito1 ,

    Just checking if you got the result you were looking for on this thread. Happy to help further if not.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • felipito1 Profile Picture
    97 on at

    Hi @WarrenBelz  

    Sorry my late reply, I have use that code on the "On change" property and it works really great!

     

    Thank you! 

  • SteefQ Profile Picture
    42 on at

    Hi WarrenBelz!

     

    I tried your solution but didn't get it to work.

    My question is, what should the column in sharepoint be? should i be a number or plain text? also should i use a maxLength to the text box?

     

    This is my code:

    If(
     Len(till_value.Text) > 3,
     UpdateContext(
     {
     vColon: Left(
     till_value.Text,
     2
     ) & ":" & Right(
     till_value.Text,
     2
     )
     }
     );
     Reset(till_value)
    )

    My problem seems to be that it dosn't trigger to the onChange event even if i press enter.

    I also added vColon on Default

     

     

  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    Hi @SteefQ ,

    This is a very old closed post, but it should work on a Text Control - I do not know of any reason the OnChange would not trigger it.

  • SteefQ Profile Picture
    42 on at

    Hi again,

    thanks for replying, sorry for posting on a old post i noticed it but thought it would be better than posting a new one.

     

    It was my fault i got it to work when i changed the property to numbers, is there anyway to make it on property text?

     

    The reason why im asking this is because the user can input letters inside the box.

    SteefQ_0-1653481118744.png

     

     

  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    Hi @SteefQ ,

    A colon is Text, so you need text, however try this OnChange

    UpdateContext(
     {
     varTime: 
     If(
     IsMatch(
     Self.Text,
     Digit & Digit & Digit & Digit
     ),
     Left(
     Self.Text,
     2
     ) & ":" & 
     Right(
     Self.Text,
     2
     ),
     Blank()
     )
     }
    );
    Reset(Self)

    Default is

    varTime

    Also set DelayOutput to true

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • SteefQ Profile Picture
    42 on at

    Hi!

    Sorry for a late reply,

     

    It's working fine, but i got one question.

    The users will input the times they want to work eg: 08:00 to 17:00

    Could i do that the user could only input between 00:00 to 00:00

    and the minutes should only be between 00 to 60

     

    EG: if the user input 25:69 it should not accept or 14:68 it should not accept

     

    EDIT:

     

     

     

    If(Right(TextInput1.Text,2)>60,
    UpdateContext(
     {
     varTime: 
     If(
     IsMatch(
     Self.Text,
     Digit & Digit & Digit & Digit
     ),
     Left(
     Self.Text,
     2
     ) & ":" & 
     Right(
     Self.Text,
     2
     ),
     Blank()
     )
     }
    );
    Reset(Self),
    Reset(Self));

     

     

     

     

    This is my code now and it throws out an error: Invalid arguments type. Expecting one of the following: Number, Date, Time, DateTime.

     

    It works without the right value..

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard