The Date Picker Control

– When using a Date Picker control to select a date and store it in Dataverse, the format of the stored content depends on whether the Dataverse column has been defined as ‘Date only’ or as ‘Date and time’

As you might expect, a ‘Date only’ column purely stores the date. For example, today’s date would be stored in US format: 11/05/2023

With a ‘Date and Time’ column, because a Data Picker control doesn’t have a time element, the default time of midnight, ie the start of the day, is appended to the date giving: 11/05/2023 00:00 AM

Customising the Date and Time Selection

There could be a reason that requires a different default time than midnight

Consider the example of arranging a delivery date and time, as in the example below. A ‘Date and time’ column called Deadline in a Dataverse table called Delivery that captures the latest an item should be delivered

The column is populated by concatenating and patching the selections made in two controls, a Date Picker and a Radio Button

date dropdown control and time radio button control

Add the following table formula to the Items property of the Radio control to define the display text and value for each button

Table(
{
Key: "Before 10pm (free of charge)",
Value: "22:00"
},
{
Key: "Before 5pm (£2.99)",
Value: "17:00"
},
{
Key: "Before 1pm (£3.99)",
Value: "13:00"
}
)

Now add the following to the OnSelect property of the Submit button

Patch(
   Delivery,
Defaults(Delivery),
{
Deadline: DateTimeValue(DatePicker1.SelectedDate & " " & Radio1.Selected.Value)
}
)
using a canvas app radio button to specify a time with data entered

Selecting today’s date and the option of delivery before 1pm, patches the following to Dataverse

11/05/2023 13:00 AM

Interestingly, you might think that using this same approach with a ‘Date only’ column would fail but it doesn’t and the date and time is patched in just the same way

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top