--- title: "HOURSDIFF(A,B)" slug: "datetimetransform-template-2" updated: 2021-11-11T16:46:52Z published: 2021-11-11T16:46:52Z canonical: "docs.datajet.app/datetimetransform-template-2" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.datajet.app/llms.txt > Use this file to discover all available pages before exploring further. # HOURSDIFF(A,B) ## DateTime Transform: HOURSDIFF(A,B) ## Returns difference in hours between DateTime A and DateTime B HOURSDIFF(A,B) - AbsoluteHours(B) - AbsoluteHours(A) Where - AbsoluteHours(B) = number of hours from date reference to B - AbsoluteHours(A) = number of hours from date reference to A - date reference = Jan 0, 0000 00:00:00 ## Purpose Use this function to: - Calculate the age of events - Calculate the number of hours between events ## Return Value | Property | Value | | --- | --- | | **FieldType** | Integer | | **FieldSize** | Med / High | | **DataType** | Discrete | | **DataSize** | Integer | ```shell Example Return Value: -N....N where N = maximum difference in hours between A and B ``` ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/DT_HOURSDIFF_Sample.PNG) ## Parameters | Parameter | JSON | Description | | --- | --- | --- | | **Table** | “targetTable”: “MyTableName” | The target table on which the new field will be created | | **Filter** | “dataset”: {DataSet_JSON} | Optional. If a filter is applied, records not in the filter Recordset will be returned as null. | | **DateTime Function** | “p1”: “HOURSDIFF(A,B)” | HOURSDIFF(A,B) | | **A** | “p2”: “DateTimeFieldName” “p2”: “#YYYY-MM-DD HH:MM:SS” | Required. DateTime A *Supports:* - **DataType:** Discrete / Continuous - **Field Type:** DateTime - **Fixed Value:** #YYYY-MM-DD HH:MM:SS, e.g. #2021-04-05 11:01:08 | | **B** | “p3”: “DateTimeFieldName” “p3”: “#YYYY-MM-DD HH:MM:SS” | Required. DateTime B *Supports:* - **DataType:** Discrete / Continuous - **Field Type:** DateTime - **Fixed Value:** #YYYY-MM-DD HH:MM:SS, e.g. #2021-04-05 11:01:08 | ## JSON Sample ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/DT_HOURSDIFF_JSON.png) ## Usage Notes Any combination of Field/Immediate value is valid for A and B e.g., - `A=FieldA, ``B=#2019-01-02 00:00:00` - `A=#2020-01-02 00:00:00,  B = #2019-01-02 00:00:00` - `A=FieldA, B=FieldB` - `A=#2020-01-02 00:00:00, B=FieldB` HOURSDIFF can be manually calculated using DAYSDIFF, (A-B), (A*B), HOUR, (A+B+C) : ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/DT_HOURSDIFF_Usage1.png) ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/DT_HOURSDIFF_Usage2.png) See Also; - MINSDIFF(A,B)  (DateTime) - SECSDIFF(A,B)  (DateTime) - Engineering | Expression Field ## Example | Example | Details | | --- | --- | | **Description** | Calculate number of hours between purchase and shipping | | **Input** | - Table: = [transactions] - Function: = DateTimeTransform - **DateTimeFunction: =** - A:= [transactions].[dtPurchase] - B: = [transactions].[dtShipping] - Name: =ShippingTime_Hour | | **Sample** | ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/DT_HOURSDIFF_Example.PNG) |