function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Narendra Reddy 13Narendra 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
RohRoh
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.

PLEASE SELECT THIS AS THE BEST ANSWER, IF YOU LIKE IT.

Thanks,
Rohit Alladi

All Answers

David ZhuDavid 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 13Narendra Reddy 13
It is not working.

Can you suggest me for formula field.
RohRoh
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.

PLEASE SELECT THIS AS THE BEST ANSWER, IF YOU LIKE IT.

Thanks,
Rohit Alladi
This was selected as the best answer
RohRoh
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,
Rohit Alladi