--- title: "HOURSBEFOREMAX(A)" slug: "datetimetransform-template-1" updated: 2021-11-11T14:30:46Z published: 2021-11-11T14:30:46Z canonical: "docs.datajet.app/datetimetransform-template-1" --- > ## 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. # HOURSBEFOREMAX(A) ## DateTime Transform: HOURSBEFOREMAX(A) ## Returns the number of hours before the maximum value of DateTime A `HOURSBEFOREMAX(A) =  HoursDiff(Max(A),A)` where - Max(A) = Maximum value in Field A - A = Value of current record - HoursDiff(Max(A),A) = total number of hours between Max(A) and A ## Purpose Use this function to: - Calculate hourly difference between an individual transaction and the most recent transaction - Calculate the age, in hours, of an event ## Return Value | Property | Value | | --- | --- | | **FieldType** | Integer | | **FieldSize** | Med / High | | **DataType** | Discrete / Continuous | | **DataSize** | Integer | ```shell Example Return Value: -N....N where N = maximum difference in hours between records in Field A ``` ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/DT_HOURSBEFOREMAX_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”: “HOURSBEFOREMAX(A)” | HOURSBEFOREMAX(A) | | **A** | “p2”: “DateTimeFieldName” “p2”: “#YYYY-MM-DD HH:MM:SS” | Required. The DateTime field from which to extract the Max Hour and the Hour to compare it with. Must be on the target table. *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_HOURSBEFOREMAX_JSON.PNG) ## Usage Notes See also: - HOURSDIFF(A,B)   (DateTime) - Engineering | Expression Field ## Example | Example | Details | | --- | --- | | **Description** | Calculate number of hours between current row and maximum DateTime for the field | | **Input** | - Table: = [transactions] - Function: = DateTimeTransform - **DateTimeFunction: =HOURSBEFOREMAX(A)** - A:= [transactions].[DateTime] - Name: =HoursBeforeMax | | **Sample** | ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/DT_HOURSBEFOREMAX_Example.PNG) |