# DateDiff

Returns the numeric difference in the requested date part between two dates

## Method Signature

```
DateDiff(datepart=[string], date1=[any], date2=[any])
```

### Arguments

| Argument   | Type     | Required | Description                             | Default |
| ---------- | -------- | -------- | --------------------------------------- | ------- |
| `datepart` | `string` | `true`   |                                         |         |
| `date1`    | `any`    | `true`   | The reference date object               |         |
| `date2`    | `any`    | `true`   | The date which to compare against date1 |         |

## Examples

### dateDiff Example

Find the difference between two dates.

[Run Example](https://try.boxlang.io/?code=eJxLSSxJdclMS9NQUEpR0lFQMjIwNNY1MNQ1NEXmGZkqKWhacwEA%2FP0JhQ%3D%3D)

```java
dateDiff( "d", "2013-01-15", "2013-01-25" );

```

Result: 10

### How old are they?

Calculates a persons age based on a variable birthDate which contains a date. Uses the now function to get current date.

[Run Example](https://try.boxlang.io/?code=eJxLyiwqyXBJLElVsFVILkoFMkAcDQVDS3MjHQVTHQUjAwVNa67EdJCCFJB0ZlqahoJSJRAo6SgkwbTrKOTll2togtSWF2WWpOaXlhSUlmgogDQCxQBb5x9R)

```java
birthDate = createDate( 1972, 5, 20 );
age = dateDiff( "yyyy", birthDate, now() );
writeoutput( age );

```

### dateDiff member function

[Run Example](https://try.boxlang.io/?code=eJw9jEsKg0AQRPeeonA1wiTiOrgICa6EnEHSLQ6EnjDTjdf3g7oqePWqlLO%2BB2W0kDi76lFQGMeD0BpPIoeSSo%2FGQ0979eYUlD%2Bmf1N3FfdtffjXUbXpqGvoFDISqyXJaBAFvX2ZPQYh3Hbwij%2FqLIcoxQLZ7DCY)

```java
testDate = now();
diffDate = dateAdd( "d", 1, testDate );
writeOutput( testDate.diff( "d", diffDate ) );
```

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJxLTc7I11BwSSxJdclMS9NQUEpR0lFQMjIwNNM1MNM1MkfhWSgpaCqoKSjZJBXZAZnWCvr6CoZcqaQYYY7FCAPSjDDDYoQuFmdkoJqhYGBgBUbowoZQYaL8RqyhBjgNxeJbDEMNSTUUm%2F%2FLUwi61RxPAHCBzDUy4gIAgmpzzQ%3D%3D)

```java
echo( DateDiff( "d", "2016-06-27", "2016-06-28" ) & "<br>" ); // 1
echo( DateDiff( "d", "2016-06-27", "2016-06-27" ) & "<br>" ); // 0
echo( DateDiff( "d", "2016-06-27", "2016-06-26" ) & "<br>" ); // -1
echo( DateDiff( "h", "2016-06-27 00:00:00", "2016-06-27 01:00:00" ) & "<br>" ); // 1
echo( DateDiff( "h", "2016-06-27 00:00:00", "2016-06-27 00:00:00" ) & "<br>" ); // 0
echo( DateDiff( "h", "2016-06-27 01:00:00", "2016-06-27 00:00:00" ) & "<br>" ); // -1
echo( DateDiff( "wd", "2016-06-27 00:00:00", "2016-07-27 01:00:00" ) & "<br>" );
 // 22

```

## Related

* [ClearTimezone](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/cleartimezone)
* [CreateDate](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/createdate)
* [CreateDateTime](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/createdatetime)
* [CreateODBCDate](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/createodbcdate)
* [CreateODBCDateTime](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/createodbcdatetime)
* [CreateODBCTime](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/createodbctime)
* [CreateTime](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/createtime)
* [CreateTimeSpan](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/createtimespan)
* [DateAdd](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/dateadd)
* [DateCompare](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/datecompare)
* [DateConvert](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/dateconvert)
* [DateFormat](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/dateformat)
* [DatePart](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/datepart)
* [DateTimeFormat](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/datetimeformat)
* [Day](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/day)
* [DayOfWeek](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/dayofweek)
* [DayOfWeekAsString](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/dayofweekasstring)
* [DayOfWeekShortAsString](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/dayofweekshortasstring)
* [DayOfYear](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/dayofyear)
* [DaysInMonth](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/daysinmonth)
* [DaysInYear](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/daysinyear)
* [FirstDayOfMonth](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/firstdayofmonth)
* [GetNumericDate](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/getnumericdate)
* [GetTime](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/gettime)
* [GetTimezone](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/gettimezone)
* [GetTimezoneInfo](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/gettimezoneinfo)
* [Hour](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/hour)
* [Millisecond](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/millisecond)
* [Minute](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/minute)
* [Month](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/month)
* [MonthAsString](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/monthasstring)
* [MonthShortAsString](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/monthshortasstring)
* [Nanosecond](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/nanosecond)
* [Now](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/now)
* [Offset](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/offset)
* [ParseDateTime](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/parsedatetime)
* [Quarter](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/quarter)
* [Second](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/second)
* [SetTimezone](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/settimezone)
* [TimeFormat](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/timeformat)
* [TimeUnits](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/timeunits)
* [Week](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/week)
* [Year](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/year)
