> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/datediff.md).

# 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`   | The datepart code in which to express the difference (yyyy, q, m, d, y, w, ww, wd, h, n, s, l). |         |
| `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](/boxlang-language/reference/built-in-functions/temporal/cleartimezone.md)
* [CreateDate](/boxlang-language/reference/built-in-functions/temporal/createdate.md)
* [CreateDateTime](/boxlang-language/reference/built-in-functions/temporal/createdatetime.md)
* [CreateODBCDate](/boxlang-language/reference/built-in-functions/temporal/createodbcdate.md)
* [CreateODBCDateTime](/boxlang-language/reference/built-in-functions/temporal/createodbcdatetime.md)
* [CreateODBCTime](/boxlang-language/reference/built-in-functions/temporal/createodbctime.md)
* [CreateTime](/boxlang-language/reference/built-in-functions/temporal/createtime.md)
* [CreateTimeSpan](/boxlang-language/reference/built-in-functions/temporal/createtimespan.md)
* [DateAdd](/boxlang-language/reference/built-in-functions/temporal/dateadd.md)
* [DateCompare](/boxlang-language/reference/built-in-functions/temporal/datecompare.md)
* [DateConvert](/boxlang-language/reference/built-in-functions/temporal/dateconvert.md)
* [DateFormat](/boxlang-language/reference/built-in-functions/temporal/dateformat.md)
* [DatePart](/boxlang-language/reference/built-in-functions/temporal/datepart.md)
* [dateSetDay](/boxlang-language/reference/built-in-functions/temporal/datesetday.md)
* [dateSetHour](/boxlang-language/reference/built-in-functions/temporal/datesethour.md)
* [dateSetMinute](/boxlang-language/reference/built-in-functions/temporal/datesetminute.md)
* [dateSetMonth](/boxlang-language/reference/built-in-functions/temporal/datesetmonth.md)
* [dateSetSecond](/boxlang-language/reference/built-in-functions/temporal/datesetsecond.md)
* [dateSetYear](/boxlang-language/reference/built-in-functions/temporal/datesetyear.md)
* [DateTimeFormat](/boxlang-language/reference/built-in-functions/temporal/datetimeformat.md)
* [Day](/boxlang-language/reference/built-in-functions/temporal/day.md)
* [DayOfWeek](/boxlang-language/reference/built-in-functions/temporal/dayofweek.md)
* [DayOfWeekAsString](/boxlang-language/reference/built-in-functions/temporal/dayofweekasstring.md)
* [DayOfWeekShortAsString](/boxlang-language/reference/built-in-functions/temporal/dayofweekshortasstring.md)
* [DayOfYear](/boxlang-language/reference/built-in-functions/temporal/dayofyear.md)
* [DaysInMonth](/boxlang-language/reference/built-in-functions/temporal/daysinmonth.md)
* [DaysInYear](/boxlang-language/reference/built-in-functions/temporal/daysinyear.md)
* [FirstDayOfMonth](/boxlang-language/reference/built-in-functions/temporal/firstdayofmonth.md)
* [GetNumericDate](/boxlang-language/reference/built-in-functions/temporal/getnumericdate.md)
* [GetTime](/boxlang-language/reference/built-in-functions/temporal/gettime.md)
* [GetTimezone](/boxlang-language/reference/built-in-functions/temporal/gettimezone.md)
* [GetTimezoneInfo](/boxlang-language/reference/built-in-functions/temporal/gettimezoneinfo.md)
* [Hour](/boxlang-language/reference/built-in-functions/temporal/hour.md)
* [Millisecond](/boxlang-language/reference/built-in-functions/temporal/millisecond.md)
* [Minute](/boxlang-language/reference/built-in-functions/temporal/minute.md)
* [Month](/boxlang-language/reference/built-in-functions/temporal/month.md)
* [MonthAsString](/boxlang-language/reference/built-in-functions/temporal/monthasstring.md)
* [MonthShortAsString](/boxlang-language/reference/built-in-functions/temporal/monthshortasstring.md)
* [Nanosecond](/boxlang-language/reference/built-in-functions/temporal/nanosecond.md)
* [Now](/boxlang-language/reference/built-in-functions/temporal/now.md)
* [Offset](/boxlang-language/reference/built-in-functions/temporal/offset.md)
* [ParseDateTime](/boxlang-language/reference/built-in-functions/temporal/parsedatetime.md)
* [Quarter](/boxlang-language/reference/built-in-functions/temporal/quarter.md)
* [Second](/boxlang-language/reference/built-in-functions/temporal/second.md)
* [SetTimezone](/boxlang-language/reference/built-in-functions/temporal/settimezone.md)
* [TimeFormat](/boxlang-language/reference/built-in-functions/temporal/timeformat.md)
* [TimeUnits](/boxlang-language/reference/built-in-functions/temporal/timeunits.md)
* [Week](/boxlang-language/reference/built-in-functions/temporal/week.md)
* [Year](/boxlang-language/reference/built-in-functions/temporal/year.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/temporal/datediff.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
