Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Time-Only Input on Model-Driven App

(5) ShareShare
ReportReport
Posted on by 19
Hi,
 
On my Model-Drive app, I need to be able to allow the user to input time only (hh:mm am/pm). I cannot find an out of the box way to achieve this. I found a couple of custom pcf components, but they store the time in multiple numeric columns (hours, minutes, seconds). After that, I want to be able to store the time in another column as 1/1/1900 hh:mm:ss (24 hour time format).
 
How can this be achieved?
 
Any assistance is appreciated!
  • ankeet1pi9 Profile Picture
    19 on at
    Time-Only Input on Model-Driven App
    @Tom_Gioielli - I am doing something similar, but w/o a PCF control. I created two separate Choice fields Hours/Minutes and then the idea is to use JavaScript OnSave event to update the DateTime field. Let's see how that works. 
     
    I am just puzzled why doesn't PowerApps have this basic functionality out of the box!
  • Suggested answer
    Tom_Gioielli Profile Picture
    1,803 on at
    Time-Only Input on Model-Driven App
    Can you use the PCF control to allow the user to enter information easily, and then use a Power Automate flow to convert it into the 24-hour time format that you need and put it into a new date/time field?
  • ankeet1pi9 Profile Picture
    19 on at
    Time-Only Input on Model-Driven App
    NOT RESOLVED YET
     
    UPDATE: I mentioned in my original post that I tried using PCF controls. Here's one that I was referring to - https://pcf.gallery/time-picker/
  • Suggested answer
    Daivat Vartak (v-9davar) Profile Picture
    7,805 Super User 2025 Season 1 on at
    Time-Only Input on Model-Driven App
    Hello Ankeet,
     

    You've identified a common challenge: Dynamics 365 doesn't have a direct "time-only" field type. You're also right to be concerned about the limitations of some PCF controls that split the time into multiple columns. Let's explore how to achieve your desired outcome:

    Understanding the Challenge:

    • No Time-Only Field: Dynamics 365 stores date and time together.

    • PCF Limitations: Some PCF controls don't store time in a standard format.

    • Desired Format: You need to store the time as 1/1/1900 hh:mm:ss (24-hour format) in a DateTime field.

    •  

    Solutions:

    1. Custom PCF Control (Recommended):

      • Create a Custom Time Picker PCF:

        • Develop a custom PCF control that provides a user-friendly time picker interface.

        • The control should:

          • Allow users to select time in hh:mm am/pm format.

          • Convert the selected time to 1/1/1900 hh:mm:ss (24-hour format).

          • Store the formatted time in a DateTime field. 

        • This is the most user friendly method. 

      • Advantages:

        • Provides a seamless user experience.

        • Stores the time in the desired format.

        • You will have complete control over the input, and output. 

      • Considerations:

        • Requires PCF development skills.

        • Requires testing and maintenance.

        •  

    2. JavaScript and a DateTime Field:

      • Add a DateTime Field:

        • Add a DateTime field to your entity. 

      • Create a Time Input Field (HTML):

        • Add a single line of text field to the form.

        • Then use JavaScript to change the single line of text field into a HTML time input field. 

      • JavaScript Logic:

        • Use JavaScript to:

          • Capture the time entered by the user.

          • Convert the time to 24-hour format.

          • Construct a DateTime string in the format 1/1/1900 hh:mm:ss.

          • Set the value of the DateTime field. 
           

      • Advantages:

        • No need for a PCF control.

        • Provides more control over the input. 

      • Considerations:

        • Requires JavaScript skills.

        • Can be complex.

        • Requires more testing.

        • HTML input controls can have cross browser compatibility issues. 
         

    3. Two Numeric Fields and a Calculated Field:

      • Add Numeric Fields:

        • Add two numeric fields to your entity: "Hours" and "Minutes." 

      • Add a Calculated Field:

        • Add a calculated DateTime field.

        • Then use the calculated field to combine the hours and minutes into the desired date time format. 

      • JavaScript (Optional):

        • Use javascript to help with user input validation. 

      • Advantages:

        • No need for a PCF control.

        • Relatively simple to implement. 

      • Disadvantages:

        • Less user-friendly than a time picker.

        • Requires manual input of hours and minutes.

        • Does not have the am/pm functionality.

        •  

    4.  

    Example JavaScript (Conceptual):

    function setTime(executionContext) {
        var formContext = executionContext.getFormContext();
        var timeInput = formContext.getAttribute("your_time_input_field").getValue(); // Get the time string
        if (timeInput) {
            // Convert time to 24-hour format and construct DateTime string
            var timeParts = timeInput.split(":");
            var hours = parseInt(timeParts[0]);
            var minutes = parseInt(timeParts[1]);
            var ampm = timeParts[2].toLowerCase();
            if (ampm === "pm" && hours < 12) {
                hours += 12;
            } else if (ampm === "am" && hours === 12) {
                hours = 0;
            }
            var dateTimeString = "1/1/1900 " + hours.toString().padStart(2, '0') + ":" + minutes.toString().padStart(2, '0') + ":00";
            formContext.getAttribute("your_datetime_field").setValue(new Date(dateTimeString));
        }
    }

     

    Key Recommendations:

    • Custom PCF Control: This is the most user-friendly and robust solution.

    • JavaScript and DateTime Field: This is a viable option if you're comfortable with JavaScript.

    • Two Numeric Fields and Calculated Field: This is the simplest option, but it's less user-friendly.

    •  

    By using these solutions, you can effectively implement time-only input and store the time in your desired format.

     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more. If you have further questions, please feel free to contact me.
     
    My response was crafted with AI assistance and tailored to provide detailed and actionable guidance for your Microsoft Dynamics 365 query.
     
    Regards,
    Daivat Vartak

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans