ShowAll Questionssorted byDate Posted
Narendra Reddy 13

# Can any one tell me. How to calculate the working hours between login and logout timings in 12 hours format?

I have below these four fileds.
Morning_Sign_In__c
Afternoon_Sign_Off__c
Afternoon_Sign_In__c
Evening_Sign_Off__c

When the employee morning sign in and afternoon sign off for lunch break and after lunch login and evening logout. in between this situation i need calculate the total working hours of the day in 12 hours format
Best Answer chosen by Narendra Reddy 13
Roh
Hello Narendra,
Create a formula field with return type as text.
I am assuming each record during save will have values into all these fields, in that case the below formula should work.

((DATEVALUE(Evening_Sign_Off__c))-(DATEVALUE(Evening_Sign_Off__c))) + (DATEVALUE(Afternoon_Sign_Off__c)-(DATEVALUE(Morning_Sign_In__c)))

Try above.

Thanks,

David Zhu
You may use gettime() method.
gettime(): Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this DateTime object.

ie. long moringsigin = Morning_Sign_In__c.gettime();
​long afternoonsignoff = Afternoon_Sign_Off__c.gettime();
long signinmsec = afternoonsignoff - moringsigin;
//convert signinmsec to hours

hope this helps.

Narendra Reddy 13
It is not working.

Can you suggest me for formula field.
Roh
Hello Narendra,
Create a formula field with return type as text.
I am assuming each record during save will have values into all these fields, in that case the below formula should work.

((DATEVALUE(Evening_Sign_Off__c))-(DATEVALUE(Evening_Sign_Off__c))) + (DATEVALUE(Afternoon_Sign_Off__c)-(DATEVALUE(Morning_Sign_In__c)))

Try above.

Thanks,
This was selected as the best answer
Roh
Hello Narendra,
Did the above solution work for you?
In that case, please mark it as RESOLVED AND CHOOSE AS THE BEST ANSWER, so that it will helps others as well.

Thanks,