# DateDiff

## Y ## What Is the Power Fx DateDiff Function?

The Power Fx DateDiff function is a function used to calculate the difference between two dates. It takes three arguments: the unit of time to calculate the difference in, the start date, and the end date. The unit of time can be specified as days, hours, minutes, seconds, or milliseconds.

## Using the Power Fx DateDiff Function

To use the Power Fx DateDiff function, you first need to understand the syntax. Here is an example:

``` DateDiff(Unit of Time, Start Date, End Date) ```

Let’s break this down:

– **Unit of Time**: This is the unit of time that you want to calculate the difference in. It can be specified as days, hours, minutes, seconds, or milliseconds.

– **Start Date**: This is the starting date of the period you want to calculate the difference for. It must be a date/time value.

– **End Date**: This is the ending date of the period you want to calculate the difference for. It must also be a date/time value.

### Example

Let’s say that you want to calculate the number of days between two dates. Here is an example of how you would use the Power Fx DateDiff function:

``` DateDiff( Days, DateValue("2021-01-01"), DateValue("2021-01-15") ) ```

This would return the value 14, which represents the number of days between January 1st and January 15th.

### Other Units of Time

You can also use the Power Fx DateDiff function to calculate the difference in other units of time. Here are some examples:

– **Hours**: `DateDiff(Hours, Start Date, End Date)`

– **Minutes**: `DateDiff(Minutes, Start Date, End Date)`

– **Seconds**: `DateDiff(Seconds, Start Date, End Date)`

– **Milliseconds**: `DateDiff(Milliseconds, Start Date, End Date)`

### Common Scenarios

The Power Fx DateDiff function is often used in a variety of scenarios. Here are some common examples:

#### Age Calculation

One common scenario is to calculate a person’s age based on their date of birth. Here is an example of how you would use the Power Fx DateDiff function to do this:

``` Floor( DateDiff( Years, DateValue("1980-01-01"), Now() ) ) ```

This would return the person’s age in years, based on their date of birth (January 1st, 1980) and the current date.

#### Time Since Last Update

Another common scenario is to calculate the amount of time that has elapsed since a record was last updated. Here is an example of how you would use the Power Fx DateDiff function to do this:

``` DateDiff( Minutes, LastModifiedDateTime, Now() ) ```

This would return the number of minutes that have elapsed since the record was last modified.

The Power Fx DateDiff function is a powerful tool for performing date calculations in Power Apps. By understanding its syntax and the different units of time that it supports, you can use it to solve a variety of business problems.