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
Emma Watson 2Emma Watson 2 

Time spent ??

Hi All,

I am trying to calculate the time spent on each staff. I have taken 2 datetime fields and 3rd field to calulate time spent for each staff. 

What I am trying to do is : When record is getting created that time,status is 'NEW' and setting the 1st field to NOW(). Now on staff change and status not equals to 'NEW', updating fields i.e the 2nd datetime field to NOW(),Then calulating the timespent: 2nd datetime - 1st datetime and again
setting the 1st datetime field to NOW(). 

But the problem is while updating 3 fields at a time. The 2nd datetime field should be updated at the last but it is updating before calculating the time spent.

So, how to proceed with it. Please suggest for the same.


Are you doing this with trigger or workflow ? 
Emma Watson 2Emma Watson 2
Thanks for update..
I am trying it using workflow. Please suggest for the same.
Using workflow it doesnt show up the exact time spent by each agent as the values will be reset each time when an agent changes. To track the exact time for each agent then you need to setup 3 custom fields (2 date/ time fields, 1 formula field ) and supporting workflow rules for each agent to track the time spent.

Emma Watson 2Emma Watson 2
Here, the 3rd field which I have taken is a text field i.e named as time spent. This time spent is holding the difference between 1st datetime and 2nd datetime field. 

As per your update, how to proceed with formula field.

Actually, what is happening is as I have updating 3 fields in 2nd workflow rule. The 1st datetime which I am updating after time spent field, that 1st datetime field is getting updated before the calculation of time spent.

So, please suggest for the same.

No need to update the 3rd field just make it formula field and remove from workflow field update. So that 3rd field gets calculated whenever there is a value in both 1st and 2nd field.
Use below formula in 3rd field.
IF(OR(ISBLANK(1st field),ISBLANK(2nd field),1st field > 2nd field),0,2nd field - 1st field)
Hi Emma Watson 2,

It's Little delay Response to your Post ..My Solution Sholud be helps to your requirement.

1. Already You have one Field (  Ex: - In_Time__c  )
2. An Another One Field Also  (  Ex: - Out_Time__c )
3. You Need To update the time calculation in third field (Ex: - Total_Hours_Spent__c)

Solution: - 

We can achieve this Process by using formula field ( Total_Hours_Spent__c ) . Create New Formula field as per Your requirement's .Please Do folowing Steps in your formula field.
1. (Out_Time__c -  In_Time__c ) * 1440   (Showing Result's By Minutes )


2.  (Out_Time__c -  In_Time__c ) * 24     (Showing result's By an Hours)

Cheers !!!!! Be Cool And Solve This requirement as well Emma Watson, please Deactivate or Delete The Workflow you were created for this Process.


Hi Emma Watson,


An Output Will Be Display Like below... Please ask feel free if you have any concern.

User-added image