Custom Start and End Date Time Fields

Custom Start and End Date Time Fields

This feature is used if you want to add Start and End Times to the Easy Calendar or Batch Entry. Stop watch will automatically log the Start and End Times in the Time Tracking object records.

Note: This is a workaround. Start and End date fields are not a native function of Time Tracking and by creating separate Start Time and End Time fields you will need to create a formula field to use this new field to calculate the hours or the Hours (As Number).

This documentation assumes you have already created a Start Time and End Time (Time/Date fields) on the Time Tracking Summary object.

🛠️ How-To: Create a Salesforce Formula Field for Calculated Hours

This document outlines the steps to create a custom Number formula field with two decimal places. This field will calculate the difference between two DateTime fields (Start Time and End Time) and convert the result into total hours. If either DateTime field is blank, the formula will instead use the value from an existing Hours (Number) field.

1. Understand the Core Formula Logic

Salesforce stores the difference between two DateTime fields in days. To convert this difference into hours, we need to multiply the result by 24 (hours per day).

The overall structure of the formula will be:

  1. Check for Blanks: Use the ISBLANK function to see if either Start_Time__c or End_Time__c is empty.

  2. Fallback Value: If they are blank, use the value from the existing TTracking__Hours_Number__c field.

  3. Calculation: If they are not blank, calculate: (End_Time__c - Start_Time__c) * 24.

  4. Format: Ensure the output is a Number with 2 decimal places.

2. Formula Setup Steps

Step 2.1: Navigate to the Object Manager

  1. From Setup, enter Object Manager in the Quick Find box.

  2. Select the Object where you want this formula field (e.g., Case, Custom Object, etc.).

Step 2.2: Create a New Field

  1. In the selected Object, click Fields & Relationships.

  2. Click the New button.

  3. Choose Formula as the Field Type, and click Next.

Step 2.3: Define the Formula Field Details

  1. Field Label: Enter a descriptive name (e.g., Calculated Hours).

  2. Field Name: (This will auto-populate, e.g., Calculated_Hours__c).

  3. Formula Return Type: Select Number.

  4. Decimal Places: Set this to 2.

  5. Click Next.

Step 2.4: Enter the Formula

Enter the following formula into the editor. This formula uses the IF and ISBLANK functions to implement the fallback logic.

Note: Replace Start_Time__c and End_Time__c with the exact API names of your fields.

Code snippet
IF( OR( ISBLANK(Start_Time__c), ISBLANK(End_Time__c) ), TTracking__Hours_Number__c, (End_Time__c - Start_Time__c) * 24 )

Step 2.5: Verify and Save

  1. Click Check Syntax to ensure the formula is valid.

  2. (Optional) Click Add Description and Add Help Text for documentation.

  3. Click Next.

Step 2.6: Set Field-Level Security

  1. Set the Field-Level Security for the new field for all necessary profiles (typically Read-Only access for a formula field).

  2. Click Next.

Step 2.7: Add to Page Layouts

  1. Select the Page Layouts where you want the new field to be displayed.

  2. Click Save.


3. Add the new field to Reports

Ensure you add this new Calculated Hours field to the necessary reports and or list views and page layouts in Salesforce.

 

This is not a supported feature of Time Tracking and is individually customized per Salesforce org, so it is not included in your subscriptions support.