Skip to main content
Since SF doesnt support time fields, I created two text fields where users can log in their time in and out. Now I need to create a formula field that calculates the difference of the times?

 

Please note the time entries are done in military style i.e. 24 hours. Plus I believe I will be needing a validation rule or something to ensure the correct format of the time entries, right?

 

Can somebody please help me on this?
3 respuestas
  1. 14 nov 2012, 00:46
    Hello,

     

    Here is what I will do..

     

    Create a formula field of data type number with a syntax like this.. (with the assumption that the diference of time is calculated and displayed in minutes)

     

    (VALUE(LEFT(Time_Out__c,2)) - VALUE(LEFT(Time_In__c,2)))*60 

     

    +

     

    (VALUE(RIGHT(Time_Out__c,2)) - VALUE(RIGHT(Time_In__c,2))) 

     

    The syntax before + sign will give you the difference of hours (converted into minutes) while syntax after the + will give you minutes with both being added together to give you total minutes.

     

    Yes, you will be needing validation rule infact multiple rules,

     

    1) for Time In format,

     

    NOT(OR(LEN(Time_In__c)=0, 

     

    REGEX(Time_In__c, "[0-9]{2}.[0-9]{2}")))

     

    2) for time out format... same as above.. just replace the field name

     

    3) Since you are using 24 hour system, create another validation rule with syntax..

     

    CONTAINS(TEXT(Time_Spent__c), "-")

     

    This will ensure that there is never a -ve sign in the calculated field.

     

    Hope this helps!
0/9000