# Power Apps DateDiff() Function [Various Examples]

Recently, I developed a Power Apps Leave Request Form, in which I had to verify the number of days the employee applied for leave. In that scenario, the DateDiff function helps calculate the difference between two dates.

In this Power Apps tutorial, I will explain the Power Apps DateDiff() Function and its syntax. Also, we will discuss how to use DateDiff function in Power Apps with various scenarios like:

• Power Apps time difference between two dates
• Power Apps DateDiff Minutes.
• Power Apps DateDiff Date-picker.
• Exclude weekends using the Power Apps DateDiff function.

## Power Apps DateDiff() Function

The Power Apps DateDiff function allows users to calculate the difference between two dates, where they can check the number of days, months, or years between two dates.

The common examples used for this function are:

1. Duration of a project to check the days between the project start and end dates.
2. To measure the duration of a task, calculate the hours between the start and completion times.
3. Calculate a patient’s age in a healthcare app based on their birthdate, etc.

Below is the syntax for the DateDiff function:

``DateDiff( StartDateTime, EndDateTime [, Units ] )``

Where,

1. StartDateTime = Provide the starting date and time to calculate.
2. EndDateTime = Provide the ending date and time to calculate.
3. Units = Provide the type of Units to add [Days, Hours, Milliseconds, Minutes, Months, Seconds, Quarters, and Years]

## Power Apps Time Difference Between Two Dates

Assume that there are two dates; the Current Date is “02-12-2024,” and another date is “02-12-2026.”

Here, I need to calculate the number of years between these dates. For that, insert a Text label -> Set its Text property to:

``DateDiff(Today(), Date(2026, 02, 12),TimeUnit.Years) // Result = 2 ``

## Power Apps DateDiff Minutes

Assume that there are two dates; the Current Date is “02-12-2024,” and another date is “03-12-2024.”

Here, I need to calculate the number of minutes between these dates. For that, insert a Text label -> Set its Text property to:

``DateDiff(Today(), Date(2024, 03, 12),TimeUnit.Minutes)        // Result = 41760``

## Power Apps DateDiff Datepicker

According to my needs, I have to verify the duration of employment for each employee in our company.

On the Power Apps screen, I have added two Date-picker controls [Employee Start Date & Employee End Date] and a Text label control.

When a user selects dates from both Date-picker controls, the Text label automatically calculates and displays the number of days between the employee’s start and end dates.

To achieve it, follow the below steps:

• Select the Text label control -> Set its Text property to:
``````DateDiff(
dte_EmployeeStartDate.SelectedDate,
dte_EmployeeEndDate.SelectedDate,
TimeUnit.Days
)``````

Where,

1. dte_EmployeeStartDate = Date-picker1 control name [Employee start date.]
2. dte_EmployeeEndDate = Date-picker2 control name [Employee end date.]
• Once the app is ready, SavePublish, and Preview the app when the user chooses the dates from the employee’s start and end dates. The text label will display the number of days between the selected dates on the date picker.

As per the above steps, we saw how to display the number of dates between two selected dates. However, considering the company policy, weekends are non-working days.

Therefore, the calculation should exclude weekends while determining the date difference between the two selected dates.

To achieve it, follow the below steps:

## Power Apps DateDiff excludes weekends

To exclude the weekend while checking the difference between the two dates:

• Select the Text label -> Set its Text property as:
``````RoundDown(
DateDiff(
dte_EmployeeStartDate.SelectedDate,
dte_EmployeeEndDate.SelectedDate,
TimeUnit.Days
) / 7,
0
) * 5 + Mod(
5 + Weekday(dte_EmployeeEndDate.SelectedDate) - Weekday(dte_EmployeeStartDate.SelectedDate),
5
)``````

Where,

1. dte_EmployeeStartDate = Date picker1 control name of Project Start Date
2. dte_EmployeeEndDate = Date picker2 control name of Project End Date
• Once the app is ready, SavePublish, and Preview the app when the user selects the date from the employee’s start and end dates. The text label will display the days between those dates, excluding weekends.

## Conclusion

In this Power Apps tutorial, you have learned how to use a Power Apps DateDiff function with its syntax and different scenarios like:

• Power Apps check days between the actual date and the provided date.
• Power Apps DateDiff Minutes.
• Power Apps DateDiff Date-picker.
• How to exclude weekends using Power Apps DateDiff function.

Also, you may like some more articles: