Sundial

Time Custom Field

I have been playing around with various features in the Spring ’18 release in a prerelease org in preparation for the next Lehigh Valley Salesforce Developer Group meetup. One of the features I explored is the new Time field type. The Idea for it has been around for 11 years, and it has gone into public beta with the Spring ’18 release. This is a quick hit post of some of the characteristics of the Time field type.

Custom field create new Time field
Time Field

Stored and Displayed

The Time field is represented in 24-hour notation (HH:MM), so 16:40 = 4:40 PM. You can enter 4:40 PM and it will convert, if your locale supports AM/PM notation. You can also just enter 16:40. It will use your locale to display it in Salesforce Classic. In Lightning, it uses the 24 hour notation no matter what in the view mode. In all cases, there is no timezone.

Time field edited in LEX
Time field edited in LEX
Time field view in LEX
Time field view in LEX
Time field view in Classic
Time field view in Classic

 

Math

Adding and subtracting time uses milliseconds. For example, if the time is 4:30 PM (16:40) and you need to add 10 minutes, it would be My_Time_Field__c + 1000 * 60 * 10.

  • 1,000 = 1 second
  • 60,000 = 1 minute
  • 600,000 = 10 minutes
  • 3,600,000 = 1 hour

Also worth noting is that adding and subtracting is like using the modulo operator. That is, if you add more than 24 hours, it cycles back around to 1, and likewise for subtraction.  For example.

Formulas

When creating a Formula type, you can now select Time as the return type of a formula. Also, there are functions that are similar to the DATETIME functions, such as TIMENOW() and TIMEVALUE(arg) that can be used in formulas. Both return the GMT Time.

The Time field is a simple wall clock time.  There are no time zones stored with a Time field. If the concept of a time zone is needed, a time zone or offset field would need to exist outside of the Time field such as another custom field on some object. It could be created on the same object as the one that holds the Time field or a different object (e.g., User). Note: you can search and find some clever hacks (e.g., this answer), but beware of adding complexity. The custom time zone calculation/field could then be used in a formula in conjunction with the Time field, if desired.

If the declarative features alone do not meet the requirements, Apex can be used to manipulate the Time field. There is a TimeZone class and there is also a Time class.

More

There are some limitations, such as it cannot be used in a Lightning Input Component at this time. Additionally, there are reporting considerations, and other features worth exploring. For that, check out the Time Custom Field help page and the Custom Time Field Success Community Group.

One thought on “Time Custom Field

  1. I’m not a fan of the formatting either.
    The time class seems to lack the basic conversion methods of other data types, i.e. format, parse and valueOf.

Leave a Reply

Your email address will not be published. Required fields are marked *