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

Community site session details

Session Id :

Enter time using a single drop-down with intervals (like Outlook)

WarrenBelz Profile Picture WarrenBelz 151,881 Most Valuable Professional
Have you ever wanted to replace the two Hour & Minute drop-downs with a single drop-down showing set intervals (example here is 15 minute like Outlook).
This is quite easy to do using a Date Picker and a single drop-down as below

The Date Picker is a standard item (you can leave the one that Power Apps creates when a Date/Time field is added) and there are three settings you need to know (two on the drop-down - you can use the one provided for Hours if you want to and delete the Minute item) - the Items and Default and also the Update of the Data Card.

Firstly the Items of the drop-down (in this case) reflects 15 minute intervals for 24 hours and presents as per the image above.
ForAll(
   Sequence(96),
   Text(
      Time(
         0,
         Value * 15 - 15,
         0
      ),
      "hh:mm AM/PM"
   )
)

Next, you need to display the current date/time saved in the drop-down in the Default which is (replace DateTimeField​​​​​​​ with your actual field name)
With(
   {_Hour: Hour(ThisItem.DateTimeField)},
   Text(
      If(
         _Hour = 0,
         12,
         _Hour - If(
            _Hour > 11,
            12
         )
      ),
      "00"
   ) & ":" & Text(
      Minute(ThisItem.DateTimeField),
      "00"
   ) & " " & If(
      _Hour > 11,
      "PM",
      "AM"
   )
)

As mentionend above, the date picker DefaultDate can remain as is (Parent.Default) or change to
ThisItem.DateTimeField

Finally, you need to write the data back to SharePoint, so the Update of the Data Card would be (using your date picker and drop-down names)
With(
   {
      _Hour: Value(
         Left(
            DropdownName.Selected.Value,
            2
         )
      ),
      _Minute: Value(
         Mid(
            (DropdownName.Selected.Value),
            4,
            2
         )
      ),
      _AMPM: Right(
         DropdownName.Selected.Value,
         2
      )
   },
   DatePickerName.SelectedDate + Time(
      If(
         _Hour = 12 && _AMPM = "AM",
         0,
         _Hour + If(
            _AMPM = "PM",
            12
         )
      ),
      _Minute,
      0
   )
)


Comments