> For the complete documentation index, see [llms.txt](https://docs.work-relay.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.work-relay.com/automations/functions-and-formulas/functions-library/date-and-time-functions.md).

# Date and time functions

<details>

<summary>MINUTES</summary>

Converts number into minutes value.

**Usage:**

{% code overflow="wrap" %}

```apex
MINUTES(parameter)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`parameter`</mark>* *<mark style="color:cyan;">with the number value to convert it to minutes.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
{Opportunity.RFQ_Date__c} + MINUTES(30) 
```

{% endcode %}

Will add **30** minutes to RFQ\_Date\_\_c value.

{% hint style="warning" %}
If do not convert number to minutes, error will occur.
{% endhint %}

</details>

<details>

<summary>HOURS</summary>

Converts number into hours value.

**Usage:**

{% code overflow="wrap" %}

```apex
HOURS(parameter) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`parameter`</mark>* *<mark style="color:cyan;">with the number value to convert it to hours.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
{Opportunity.RFQ_Date__c} + Hours(12)
```

{% endcode %}

Will add **12** hours to RFQ\_Date\_\_c value.

{% hint style="warning" %}
If do not convert number to hours, error will occur.
{% endhint %}

</details>

<details>

<summary>MONTH</summary>

Returns the month component of a date or datetime value.

**Usage:**

{% code overflow="wrap" %}

```apex
MONTH(parameter) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`parameter`</mark>* *<mark style="color:cyan;">with the date/datetime value.</mark>*

**Example:**

<mark style="color:orange;">Let</mark> <mark style="color:orange;">`RFQ_Date__c`</mark> <mark style="color:orange;">= 2020-07-01T03:30:05Z.</mark>

{% code overflow="wrap" %}

```apex
MONTH({Opportunity.RFQ_Date__c})
```

{% endcode %}

Returns **7** (integer representing month component of RFQ\_Date\_\_c field value).

</details>

<details>

<summary>YEAR</summary>

Returns the year component of a date or datetime value.

**Usage:**

{% code overflow="wrap" %}

```apex
YEAR(parameter) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`parameter`</mark>* *<mark style="color:cyan;">with the date/datetime value.</mark>*

**Example:**

<mark style="color:orange;">Let</mark> <mark style="color:orange;">`RFQ_Date__c`</mark> <mark style="color:orange;">= 2027-07-01T03:30:05Z.</mark>

{% code overflow="wrap" %}

```apex
YEAR({Opportunity.RFQ_Date__c})
```

{% endcode %}

Returns **2027** (integer representing year component of RFQ\_Date\_\_c field value).

</details>

<details>

<summary>DATE</summary>

Returns a date value from year, month, and day values you enter.

**Usage:**

{% code overflow="wrap" %}

```apex
DATE(year, month, day)
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`year`</mark>* *<mark style="color:cyan;">with a four-digit year</mark>*
* *<mark style="color:cyan;">`month`</mark>* *<mark style="color:cyan;">with a two-digit month</mark>*
* *<mark style="color:cyan;">`day`</mark>* *<mark style="color:cyan;">with a two-digit day</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
DATE(2016, 10, 10)
```

{% endcode %}

Returns a date value (not string) of **October 10, 2016**.

</details>

<details>

<summary>DATETIME</summary>

Returns a datetime value from year, month, day, hours, minutes and seconds values in the local time zone of the context user

**Usage:**

{% code overflow="wrap" %}

```apex
DATETIME(year, month, day, hours, minutes, seconds)
```

{% endcode %}

*<mark style="color:cyan;">Replace parameters with integer values of year, month, day, hours, minutes and seconds.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
DATETIME(2005, 1, 2, 20, 30, 0) 
```

{% endcode %}

Returns a datetime value (not string) of **January 2, 2005, 8:30 PM**.

</details>

<details>

<summary>DATETIMEGMT</summary>

Returns a datetime value from year, month, day, hours, minutes, seconds in GMT datetime value

**Usage:**

{% code overflow="wrap" %}

```apex
DATETIMEGMT(year, month, day, hours, minutes, seconds)
```

{% endcode %}

*<mark style="color:cyan;">Replace parameters with integer values of year, month, day, hours, minutes and seconds.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
DATETIMEGMT(2005, 1, 2, 20, 30, 0) 
```

{% endcode %}

Returns a datetime value (not string) of **January 2, 2005, 8:30 PM GMT**.

</details>

<details>

<summary>DATEVALUE</summary>

Returns a date value for a date, datetime or text expression.

**Usage:**

{% code overflow="wrap" %}

```apex
DATEVALUE(datetime_or_string) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`datetime_or_string`</mark>* *<mark style="color:cyan;">with a date, datetime or text value.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
DATEVALUE('11/15/2015')
```

{% endcode %}

Returns a date value (not string) of **November 15, 2015**.

</details>

<details>

<summary>DATETIMEVALUE</summary>

Returns a date and time (month, year, day and time) in the local time zone of the context user.

**Usage:**

{% code overflow="wrap" %}

```apex
DATETIMEVALUE(date_or_string)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`date_or_string`</mark>* *<mark style="color:cyan;">with a date, datetime or text value.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
DATETIMEVALUE('2005-11-15 17:00:00')
```

{% endcode %}

Returns a datetime value (not string) of **November 15, 2005 5:00 PM**.

</details>

<details>

<summary>DATETIMEVALUEGMT</summary>

Returns a year, month, day and time as GMT time value.

**Usage:**

{% code overflow="wrap" %}

```apex
DATETIMEVALUEGMT(datetime_or_string)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`datetime_or_string`</mark>* *<mark style="color:cyan;">with a date, datetime or text value.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
DATETIMEVALUEGMT('2015-11-15 17:00:00')
```

{% endcode %}

Returns a datetime value (not string) of **November 15, 2005 5:00 PM GMT**.

</details>

<details>

<summary>DATETIMETOGMT</summary>

Converts datetime value from the local time zone of a context user to the Greenwich Mean Time value with **datetime** type.

**Usage:**

{% code overflow="wrap" %}

```apex
DATETIMETOGMT(datetime_object)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`datetime_object`</mark>* *<mark style="color:cyan;">with a datetime value in context user local time zone.</mark>*

**Example:**

<mark style="color:orange;">Let current user local datetime value is 6/9/2027 10:09:14 AM PST.</mark>

{% code overflow="wrap" %}

```apex
DATETIMETOGMT({$System.DateTime}) 
```

{% endcode %}

Returns a datetime value (not string) of **6/9/2027 5:09:14 PM GMT**.

</details>

<details>

<summary>ADDDAYS</summary>

Returns a new **date** or **datetime** value that adds the specified number of days to the value of this instance

**Usage:**

{% code overflow="wrap" %}

```apex
ADDDAYS(date/datetime, number_of_days, boolean_consider_weekends) 
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`date/datetime`</mark>* *<mark style="color:cyan;">with the date or datetime you want to add days to</mark>*
* *<mark style="color:cyan;">`number_of_days`</mark>* *<mark style="color:cyan;">with integer number of days that needs to be added to original value</mark>*
* *<mark style="color:cyan;">`boolean_consider_weekends`</mark>* *<mark style="color:cyan;">with</mark>* *<mark style="color:cyan;">**true**</mark>* *<mark style="color:cyan;">if calculation should exclude Saturday and Sunday, or</mark>* *<mark style="color:cyan;">**false**</mark>* *<mark style="color:cyan;">if it should not</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
ADDDAYS(DATE(2028, 02, 12), 2, false) 
```

{% endcode %}

Returns **2028-02-14 00:00:00**.

</details>

<details>

<summary>ADDMONTHS</summary>

Adds the given number of months to the date or datetime value

**Usage:**

{% code overflow="wrap" %}

```apex
ADDMONTHS(date/datetime, number_of_months)
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`date/datetime`</mark>* *<mark style="color:cyan;">with the date or datetime you want to add months to</mark>*
* *<mark style="color:cyan;">`number_of_months`</mark>* *<mark style="color:cyan;">with the integer number of months that needs to be added to original value</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
ADDMONTHS(DATE(2028, 02, 12), 5) 
```

{% endcode %}

Returns **2028-07-12 00:00:00**.

</details>

<details>

<summary>ADDYEARS</summary>

Adds the given number of years to the date or datetime value

**Usage:**

{% code overflow="wrap" %}

```apex
ADDYEARS(date/datetime, number_of_years) 
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`date/datetime`</mark>* *<mark style="color:cyan;">with the date or datetime you want to add years to</mark>*
* *<mark style="color:cyan;">`number_of_years`</mark>* *<mark style="color:cyan;">with the integer number of years that needs to be added to original value</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
ADDYEARS(DATE(2029, 02, 12), 5) 
```

{% endcode %}

Returns **2034-02-12 00:00:00**.

</details>

<details>

<summary>ADDINTERVAL</summary>

Adds time interval to the datetime based on the business hours for the SalesForce organization.

**Usage:**

{% code overflow="wrap" %}

```apex
ADDINTERVAL(datetime, interval_string, business_hours_id_optional)
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`datetime`</mark>* *<mark style="color:cyan;">parameter with a datetime value</mark>*
* *<mark style="color:cyan;">`interval_sting`</mark>* *<mark style="color:cyan;">with time interval in the following format</mark>* *<mark style="color:cyan;">`'1d 1h 1m'`</mark>*
* *<mark style="color:cyan;">`business_hours_id_optional`</mark>* *<mark style="color:cyan;">with an id of a business hours record used in your organization</mark>*

**Example:**

<mark style="color:orange;">Let current system datetime value is Tuesday, 04/01, 8 AM; business hours setup is 8 AM to 11 AM, Monday to Friday.</mark>

{% code overflow="wrap" %}

```apex
FORMULA[FORMAT(ADDINTERVAL({$System.DateTime}, '5h 30m', 'id_of_business_hours_record'))] 
```

{% endcode %}

Returns **Wednesday, 04/02, 10:30 AM** value.

{% hint style="info" %}
To access business hours records navigate to Setup > Company Profile > Business Hours.

Note: a `business_hours_id_optional` parameter is optional.\
If pass an empty string or null, interval will be added using 24-hours day, 7-days week, 365-days year.
{% endhint %}

</details>

<details>

<summary>SUBTRACTINTERVAL</summary>

Subtracts time interval from the datetime based on the business hours for the SalesForce organization.

**Usage:**

{% code overflow="wrap" %}

```apex
SUBTRACTNTERVAL(datetime, interval_string, business_hours_id_optional) 
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`datetime`</mark>* *<mark style="color:cyan;">parameter with a datetime value</mark>*
* *<mark style="color:cyan;">`interval_sting`</mark>* *<mark style="color:cyan;">with time interval in the following format</mark>* *<mark style="color:cyan;">`'1d 1h 1m'`</mark>*
* *<mark style="color:cyan;">`business_hours_id_optional`</mark>* *<mark style="color:cyan;">with an id of a business hours record used in your organization</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
FORMAT(SUBSTRACTINTERVAL(DATETIME(2019, 03, 12, 11, 0, 0), '3h 30m')) 
```

{% endcode %}

Returns **3/12/2019 7:30 AM**.

{% hint style="info" %}
To access business hours records navigate to Setup > Company Profile > Business Hours.

Note: a `business_hours_id_optional` parameter is optional.\
If pass an empty string or null, interval will be added using 24-hours day, 7-days week, 365-days year.
{% endhint %}

</details>

<details>

<summary>NORMALIZEDATE</summary>

Moves a date or datetime to the closer working day according to business hours.

**Usage:**

{% code overflow="wrap" %}

```apex
NORMALIZEDATE(date/datetime, business_hours_id_optional) 
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`date/datetime`</mark>* *<mark style="color:cyan;">parameter with value you need to normalize</mark>*
* *<mark style="color:cyan;">`business_hours_id_optional`</mark>* *<mark style="color:cyan;">with an id of a business hours record used in your organization</mark>*

**Example:**

<mark style="color:orange;">Let current system datetime value is Wednesday, 03/13, 2 PM; selected business hours setup is 8 AM to 11 AM, Monday to Friday.</mark>

{% code overflow="wrap" %}

```apex
NORMALIZEDATE({$System.DateTime}, id_of_business_hours_record) 
```

{% endcode %}

Return **Monday, 3/18 8:00 AM**.

{% hint style="info" %}
To access business hours records navigate to Setup > Company Profile > Business Hours.

Note: a `business_hours_id_optional` parameter is optional.\
If pass an empty string or null, default business hours setting for the organization will be used to calculate date or datetime.
{% endhint %}

</details>

<details>

<summary>STARTOFDAY</summary>

Moves a date/datetime to the start of working day according to business hours.

**Usage:**

{% code overflow="wrap" %}

```apex
STARTOFDAY(date/datetime, business_hours_id_optional) 
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`date/datetime`</mark>* *<mark style="color:cyan;">parameter with value you need to calculate</mark>*
* *<mark style="color:cyan;">`business_hours_id_optional`</mark>* *<mark style="color:cyan;">with an id of a business hours record used in your organization</mark>*

**Example:**

<mark style="color:orange;">Let current system datetime value is Wednesday, 03/13, 2 PM; selected business hours setup is 8 AM to 11 AM, Monday to Friday.</mark>

{% code overflow="wrap" %}

```apex
STARTOFDAY({$System.DateTime}, id_of_business_hours_record) 
```

{% endcode %}

Returns **Monday, 3/13 8:00 AM**.

{% hint style="info" %}
To access business hours records navigate to Setup > Company Profile > Business Hours.

Note: a `business_hours_id_optional` parameter is optional.\
If pass an empty string or null, default business hours setting for the organization will be used to calculate date or datetime.
{% endhint %}

</details>

<details>

<summary>ENDOFDAY</summary>

Moves a date/datetime to the end of working day according to business hours.

**Usage:**

{% code overflow="wrap" %}

```apex
ENDOFDAY(date/datetime, business_hours_id_optional) 
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`date/datetime`</mark>* *<mark style="color:cyan;">parameter with value you need to calculate</mark>*
* *<mark style="color:cyan;">`business_hours_id_optional`</mark>* *<mark style="color:cyan;">with an id of a business hours record used in your organization</mark>*

**Example:**

<mark style="color:orange;">Let current system datetime value is Wednesday, 03/13, 2 PM; selected business hours setup is 8 AM to 11 AM, Monday to Friday.</mark>

{% code overflow="wrap" %}

```apex
ENDOFDAY({$System.DateTime}, id_of_business_hours_record) 
```

{% endcode %}

Returns **Monday, 3/13 11:00 AM**.

{% hint style="info" %}
To access business hours records navigate to Setup > Company Profile > Business Hours.

Note: a `business_hours_id_optional` parameter is optional.\
If pass an empty string or null, default business hours setting for the organization will be used to calculate date or datetime.
{% endhint %}

</details>

<details>

<summary>FORMAT</summary>

Returns a value containing an expression formatted according to given parameter.

**Usage:**

{% code overflow="wrap" %}

```apex
FORMAT(date/datetime, format_string_optional)
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`date/datetime`</mark>* *<mark style="color:cyan;">with the original date or datetime value</mark>*
* *<mark style="color:cyan;">optional parameter</mark>* *<mark style="color:cyan;">`format_string_optional`</mark>* *<mark style="color:cyan;">with the valid format expression (check formats supported</mark>* [*here*](http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html)*<mark style="color:cyan;">)</mark>*

**Examples:**

`FORMAT(DATE(2019, 02, 12))` will return **2/12/2019**.\
\
`FORMAT(DATETIME(2019, 02, 12, 11, 23, 0))` will return **2/12/2019 11:23 AM**.\
\
`FORMAT(DATETIME(2019, 02, 12, 11, 23, 0), 'h:mm a')` **will return 11:23 AM**.

</details>

<details>

<summary>FORMATGMT</summary>

Returns a value containing an expression formatted according to given parameter in GMT time value.

**Usage:**

{% code overflow="wrap" %}

```apex
FORMATGMT(date/datetime, format_string_optional)
```

{% endcode %}

*<mark style="color:cyan;">Replace:</mark>*

* *<mark style="color:cyan;">`date/datetime`</mark>* *<mark style="color:cyan;">with the original date or datetime value</mark>*
* *<mark style="color:cyan;">optional parameter</mark>* *<mark style="color:cyan;">`format_string_optional`</mark>* *<mark style="color:cyan;">with the valid format expression (check formats supported</mark>* [*here*](http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html)*<mark style="color:cyan;">)</mark>*

**Example:**

<mark style="color:orange;">Let organization time zone is Eastern Standard Time.</mark>

{% code overflow="wrap" %}

```apex
FORMATGMT(DATETIME(2019, 03, 12, 11, 23, 0)) 
```

{% endcode %}

Returns **3/12/2019 3:23 PM**.

</details>

<details>

<summary>STARTOFWEEK</summary>

Returns **date** or **datetime** representing the first day of week for the date passed to the function in the local time zone of the context user.

**Usage:**

{% code overflow="wrap" %}

```apex
STARTOFWEEK(date/dateTime) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`date/dateTime`</mark>* *<mark style="color:cyan;">parameter with the date or datetime value which start date of the week is to be determined.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
STARTOFWEEK({Opportunity.createdDate}) 
```

{% endcode %}

Return start of the week date for the value of createdDate in GMT timezone.<br>

</details>

<details>

<summary>DAYSBETWEEN</summary>

Returns number of days between two date or datetime values.

**Usage:**

{% code overflow="wrap" %}

```apex
DAYSBETWEEN(date/datetime, date/datetime, ignoreWeekends)
```

{% endcode %}

*<mark style="color:cyan;">Replace parameters with the two dates and boolean</mark>* *<mark style="color:cyan;">`ignoreWeekends`</mark>* *<mark style="color:cyan;">with</mark>* *<mark style="color:cyan;">**true**</mark>* *<mark style="color:cyan;">if calculation should exclude Saturday and Sunday, or</mark>* *<mark style="color:cyan;">**false**</mark>* *<mark style="color:cyan;">if it should not.</mark>*

**Example:**

{% code overflow="wrap" %}

```apex
DAYSBETWEEN({Opportunity.createdDate}, {Opportunity.closedDate}, false) 
```

{% endcode %}

Returns **5** if createdDate equals 2001-07-04 and closedDate equals 2001-07-10.

</details>

<details>

<summary>DATEDIFF</summary>

Returns number of minutes, hours and days between date/datetime values.

**Usage:**

{% code overflow="wrap" %}

```apex
DATEDIFF(date/datetime, date/datetime,business_hours_id_optional,result_type_optional, hours_in_day_optional) 
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`date/datetime`</mark>* *<mark style="color:cyan;">parameters with two dates.</mark>*

{% hint style="info" %}
See below for other parameters.
{% endhint %}

**Example 1:**

{% code overflow="wrap" %}

```apex
DATEDIFF({Opportunity.createdDate}, {Opportunity.closedDate}) 
```

{% endcode %}

Returns **1440** (minutes) if `createdDate` equals 2001-07-04 and `closedDate` equals 2001-07-05.

**Example 2:**

{% code overflow="wrap" %}

```apex
DATEDIFF({Opportunity.createdDate}, {Opportunity.closedDate}, business_hours_id)
```

{% endcode %}

*<mark style="color:cyan;">Replace</mark>* *<mark style="color:cyan;">`business_hours_id_optional`</mark>* *<mark style="color:cyan;">parameter with an id of a business hours record used in your organization.</mark>*

Returns **960** (minutes) if `createdDate` equals 2020-06-29 and `closedDate` equals 2020-07-01T03:30:05Z, and business hours are set as 8 hours per day from Monday to Friday.

{% hint style="info" %}
Function can also return difference in Duration format (1d 1h 1m) or number of hours or days.
{% endhint %}

*<mark style="color:cyan;">To change format of result use '</mark><mark style="color:cyan;">`result_type_optional`</mark><mark style="color:cyan;">' parameter: replace it with one of the following values '</mark><mark style="color:cyan;">`Duration`</mark><mark style="color:cyan;">', '</mark><mark style="color:cyan;">`Hours`</mark><mark style="color:cyan;">', '</mark><mark style="color:cyan;">`Days`</mark><mark style="color:cyan;">'. This parameter is case-insensitive.</mark>*

**Example 3:**

<mark style="color:orange;">Let</mark> <mark style="color:orange;">`createdDate`</mark> <mark style="color:orange;">= 2020-06-29 and</mark> <mark style="color:orange;">`closedDate`</mark> <mark style="color:orange;">= 2020-07-01T03:30:05Z</mark>

{% code overflow="wrap" %}

```apex
DATEDIFF({Opportunity.createdDate}, {Opportunity.closedDate}, null, DURATION) 
```

{% endcode %}

will return **44h 30m**.

**Example 4:**

<mark style="color:orange;">Let</mark> <mark style="color:orange;">`createdDate`</mark> <mark style="color:orange;">= 2020-06-29 and</mark> <mark style="color:orange;">`closedDate`</mark> <mark style="color:orange;">= 2020-07-01T03:30:05Z</mark>

{% code overflow="wrap" %}

```apex
DATEDIFF({Opportunity.createdDate}, {Opportunity.closedDate}, null, Hours) 
```

{% endcode %}

Returns **44** (full number of hours).

**Example 5:**

<mark style="color:orange;">Let</mark> <mark style="color:orange;">`createdDate`</mark> <mark style="color:orange;">= 2020-06-29 and</mark> <mark style="color:orange;">`closedDate`</mark> <mark style="color:orange;">= 2020-07-01T03:30:05Z</mark>

{% code overflow="wrap" %}

```apex
DATEDIFF({Opportunity.createdDate}, {Opportunity.closedDate}, null, days) 
```

{% endcode %}

Returns **1.8716** (days).

{% hint style="info" %}
`hours_in_day_optional` is another optional parameter that can be used when one passes 'Duration' or 'Days' as a '`result_type_optional`' - it defines number of hours in a day for DATEDIFF calculation.
{% endhint %}

**Example 6:**

<mark style="color:orange;">Let</mark> <mark style="color:orange;">`createdDate`</mark> <mark style="color:orange;">= 2020-06-29 and</mark> <mark style="color:orange;">`closedDate`</mark> <mark style="color:orange;">= 2020-07-01T03:30:05Z</mark>

{% code overflow="wrap" %}

```apex
DATEDIFF({Opportunity.createdDate}, {Opportunity.closedDate}, false, 'Duration', 8) 
```

{% endcode %}

Returns '**3d**' if `createdDate` = 2001-07-04 and `closedDate` = 2001-07-05.

{% hint style="info" %}
To access business hours records navigate to Setup > Company Profile > Business Hours.

Notes:

* A `business_hours_id_optional` parameter is optional. If omit this parameter or pass null, function will calculate result using default organization Business Days.
* Function with 'Hours' result type will return full number of hours rounded down. This can be useful to avoid lates in calculated schedules, etc.
* Optional parameters can be omitted only if they are last, otherwise they should be set as **null**.
  {% endhint %}

</details>
