DateTimeValue

How to Use the Power Fx DateTimeValue  Function in Power Apps

Understanding the DateTimeValue Function

In Power Apps, the DateTimeValue function is used to convert a text string that represents a date and time value into a datetime value. The function takes a single argument, which is the text string to be converted. The resulting datetime value can be used in calculations, comparisons, and visualizations.

The DateTimeValue function supports a variety of date and time formats, including ISO 8601, US, and European formats. For example, the function can convert the following text strings into datetime values:

– “2021-08-23T10:30:00Z”

– “08/23/2021 10:30:00 AM”

– “23-08-2021 10:30:00”

Using the DateTimeValue Function in Power Apps

To use the DateTimeValue function in Power Apps, follow these steps:

1. Open the app in Power Apps Studio.

2. Navigate to the screen where you want to use the function.

3. Add a label or textbox to the screen.

4. Set the Text property of the label or textbox to a text string that represents a date and time value.

5. In the Formula bar, enter the following formula: DateTimeValue(Text)

The Text argument in the formula should reference the Text property of the label or textbox. The DateTimeValue function will convert the text string into a datetime value, which can be used in other formulas and functions.

Examples of Using the DateTimeValue Function

Here are some examples of using the DateTimeValue function in Power Apps:

Example 1: Calculating the Age of a Person

Suppose you have a textbox that contains a person’s birthdate, and you want to calculate their age in years. You can use the DateTimeValue function to convert the birthdate into a datetime value, and then use the Year function to extract the year of the birthdate. Here’s the formula:


Year(Today()) - Year(DateTimeValue(BirthdateTextbox.Text))


Example 2: Filtering a Gallery by Date

Suppose you have a gallery that displays a list of items, and you want to filter the gallery by a date range. You can use the DateTimeValue function to convert the start and end dates into datetime values, and then use the Filter function to filter the gallery. Here’s the formula:


Filter(ItemGallery, Date ❱= DateTimeValue(StartDateTextbox.Text) && Date ❰= DateTimeValue(EndDateTextbox.Text))


Example 3: Displaying a Date and Time Value

Suppose you have a label that displays a datetime value in a text string format, and you want to display the value as a date and time value. You can use the DateTimeValue function to convert the text string into a datetime value, and then use the Text function to format the value as a date and time string. Here’s the formula:


Text(DateTimeValue(DateLabel.Text), "dd/mm/yyyy hh:mm:ss")


The Power Fx DateTimeValue function in Power Apps is a powerful tool for converting text strings into datetime values. By using this function, developers can perform calculations, comparisons, and visualizations based on datetime values. In this article, we have explored how to use the DateTimeValue function in Power Apps, and provided examples of its usage. By mastering this function, developers can unlock the full potential of Power Apps to build custom business applications.

Power Apps Training Courses by G Com Solutions (0800 998 9248)