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 / Date/Time Validation w...
Power Apps
Answered

Date/Time Validation with AM PM Dropdown

(0) ShareShare
ReportReport
Posted on by 14
Good morning Power Aps Community,
 
I'm hoping I can get some help with date and time validation when an AM/PM dropdown is added in lieu of the default, 24 hour time included in the date & time picker. To provide this options to the user, I followed Rezza Dorrani's method of doing this via this video: Power Apps Tip: How to Change Date & Time to 12 Hour Format in Seconds! #Shorts
 
I was wondering if anyone has any ideas on how one would go about adding date/time validation on these controls. For example, I'd like to prevent users from submitting a date within 2 hours from the date of submission. Thank you in advance for assistance provided. Please let me know if I'm missing important info to get help.
Categories:
I have the same question (0)
  • SaiRT14 Profile Picture
    1,990 Super User 2025 Season 2 on at
    pls try the following formula to calculate the full selected date and time based on the dropdowns:
    Set(
        SelectedDateTime,
        DateAdd(
            DatePicker1.SelectedDate,
            If(
                AmPmDropdown.Selected.Value = "PM" && Value(HourDropdown.Selected.Value) < 12, 
                Value(HourDropdown.Selected.Value) + 12, 
                If(
                    AmPmDropdown.Selected.Value = "AM" && Value(HourDropdown.Selected.Value) = 12, 
                    0, 
                    Value(HourDropdown.Selected.Value)
                )
            ) * 60 + Value(MinuteDropdown.Selected.Value), 
            TimeUnit.Minutes
        )
    )
     
  • tyler_05 Profile Picture
    14 on at
    @SaiRT14 - I'm not quite following where you're asking to input that formula. Would I put that on the "OnChange" property for the time and am/pm dropdowns?
     
     
  • Suggested answer
    WarrenBelz Profile Picture
    153,079 Most Valuable Professional on at
    I have a blog on this subject that may assist you here.
     
    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    Buy me a coffee
  • Verified answer
    timl Profile Picture
    36,393 Super User 2025 Season 2 on at
    Hi  tyler_05
     
    I've based the following on Rezza's video that you posted (screenshot below).
      
    If you want to prevent users from submitting a datetime 2 hrs ahead of the current time, you would add the following to the OnSelect property of your Submit button. 
     
    This will alert the user if the time is within 2 hrs in the future. If the condition is false, it'll call SubmitForm to save the record.
     
     
    With(
        {
            selectedDate: DataValue5.SelectedDate + Time(
                If(drpAMPM.Selected.Value = "PM", 12, 0) + 
                Mod(Value(HourValue5.Selected.Value), 12),
                Value(MinuteValue5.Selected.Value),
                0
            )
        },
        If(
            DateDiff(Now(), selectedDate, Minutes) <= 120,
            Notify("The selected date and time is within 2 hours in the future.", NotificationType.Warning),
            SubmitForm(Form1)
        )
    )
     
     
     
  • tyler_05 Profile Picture
    14 on at
    timl (Couldn't find your username to tag),
     
    Thank you so much for your time to answer my question. Your answer was exactly what I was looking for. 
     
    It looks like I need to read up on that Mod function as I'm still a bit confused as to what exactly it's doing in my situation. 

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 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard