---
title: DateDiffSQL
slug: neurons-for-itsm/admin-user-help/enu/latest/datediffsql
createdAt: 2026-07-14T19:16:48.461Z
---

Returns an integer value in the same units as the **datePart** parameter. The return value is the result of subtracting the second date and time from the first date and time. This function behaves the same as the Microsoft SQL function called DATEDIFF.

This function uses the boundary crossing method to calculate the date difference, while the Diff functions (such as DiffDays, DiffMinutes, DiffYears, and so on) use the whole interval method. See [Date Functions](docId\:kQs_9ORcYlLvH63BbOyqv) for more information about using the boundary crossing method versus using the whole interval method.

## Syntax

`DateDiffSQL(datePart, firstDateTime, secondDateTime, timeZone)`

## Enabled For

For a description of the business object categories, see [Notes on "Enabled For"](docId\:u26v9feCFs6iLwA0-PVJd).

| Business Object Category                                                                    | Yes/No |
| ------------------------------------------------------------------------------------------- | ------ |
| Business Rules: Before-Save Rules                                                           | Yes    |
| Business Rules: Calculation Rules (After Save, with or without Also Recalculate on Load)    | Yes    |
| Business Rules: Calculation Rules (Before Save or Always, without Also Recalculate On Load) | Yes    |
| Business Rules: Calculation Rules (Before Save or Always, with Recalculate On Load)         | Yes    |
| Business Rules: Editing Rules                                                               | Yes    |
| Business Rules: Initialization Rules                                                        | Yes    |
| Business Rules: Read Only Rules                                                             | Yes    |
| Business Rules: Required Rules                                                              | Yes    |
| Business Rules: Validation Rules                                                            | Yes    |
| Client Expressions                                                                          | Yes    |
| Object Permissions                                                                          | Yes    |
| Services                                                                                    | Yes    |
| LDAP                                                                                        | Yes    |
| Mobile                                                                                      | Yes    |
| Quick Actions (except UI Quick Actions)                                                     | Yes    |
| UI Quick Actions                                                                            | Yes    |
| Reports                                                                                     | Yes    |
| Search/Dashboard without field references                                                   | Yes    |
| Search/Dashboard with field references                                                      | Yes    |

## Parameters

| Parameter      | Description                                                                                                                                                                                                     |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| datePart       | The interval type. Must be surrounded by quotes (" ").<br />The following interval types are supported:<br />millisecond<br />second<br />minute<br />hour<br />day<br />week<br />month<br />quarter<br />year |
| firstDateTime  | The first date and time to be compared.                                                                                                                                                                         |
| secondDateTime | The second date and time to be compared.                                                                                                                                                                        |
| timeZone       | (Optional) The time zone, in IANA format.                                                                                                                                                                       |

## Return Value

:::Paragraph{indent="1"}
Number value.
:::

:::Paragraph{indent="1"}
If the **firstDateTime** parameter is before the **secondDateTime** parameter, the returned value is positive. If the **firstDateTime** parameter is after the **secondDateTime** parameter, the returned value is negative. (This is the opposite of the DateDiff() function.)
:::

## Example

:::Paragraph{indent="1"}
To calculate the weekday of a given date within a quick action, you can use:
:::

`$(DateDiffSQL("day", "2012-1-1 12:00 AM", ToString(CurrentDate()) % 7) +1)`

:::Paragraph{indent="1"}
This results in 1 for Sunday, 2 for Monday, and so on.
:::
