Track Time with the Time Field Type (Generally Available)

The time field type tracks time that is not specific to a single date, such as preferred contact hours. Use it for time management, event planning, and project management. You can use the Time data type in formulas and for validation rules. This feature was a beta release in Spring ’18 and is now generally available with some improvements and enhancements.

Where: This feature is available in Lightning Experience, Salesforce Classic, and all versions of the Salesforce app.

Why: The time field type is a timestamp minus the date. Use it for tracking things like business operating hours. For example, you can display a hotel’s available check-in and check-out times.

Example hotel check in and check out times

Improvements since the previous release:

  • Lightning UI components support time fields.
  • In Lightning Experience and the Salesforce mobile app, time fields display as picklists. Previously, users had to type in a time value.
  • You can convert time fields to text or number fields.
  • When you filter time values for reports, you no longer need to include seconds or milliseconds.
  • Previously, subtraction of two time fields could result in a negative value. Now, subtraction is always a positive value on a 24-hour clock. For example, when calculating the number of hours a business is open, you use the following formula (also taking into account each hour is 3,600,000 milliseconds): (ClosedTime - OpenTime) / 3600000.

    ClosedTime = 5 PM, OpenTime = 8 AM, ClosedTime - OpenTime = 9 hours

    ClosedTime = 5 AM, OpenTime = 7 AM, ClosedTime - OpenTime = 22 hours

    ClosedTime = 5 AM, OpenTime = 11 PM, ClosedTime - OpenTime = 6 hours

How: Select the Time field type when you create a custom field. That’s it!

For more customization, use the Time data type in formulas and for validation rules. For example, you want to track recurring volunteer shifts. Create a custom field using the Time field type for the start of the shift. The field label is Shift Starts, and the API name is Shift_Start_Time.

All shifts are four hours, and you want to display when the shift ends. Add a custom field using the Formula field type that returns the Time data type. Use milliseconds for time in formulas (four hours equals 14,400,000 milliseconds), and you get the following formula for the Shift Ends field.

Shift_Start_Time__c + 14400000

Your fields look like the following.

Example time formula field

Set a time field default value using a formula and the HH:MM:SS.MS format, such as TIMEVALUE("10:30:00.000") for 10:30 AM.

Use the new TIMEVALUE and TIMENOW functions and the new HOUR, MINUTE, SECOND, and MILLISECOND functions for calculations related to time.

For example, if the Shift Ends field is another time field, the following validation rule ensures that a shift can’t be less than four hours.

Shift_Ends_Time__c <= (Shift_Start_Time__c + 14400000)
Be aware of the following when using a time field type.
  • You can’t add the field to records in automated flows created in Cloud Flow Designer or processes designed in Process Builder.
  • It isn’t supported in Schema Builder.
  • The time field type doesn’t support the creation of custom indexes for SOQL queries.
  • It isn’t available for standard lookup relationships in external objects.