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
DipakDipak 

How to get Difference between two time

Hi,

 

I have a custom object having 3 fields TimeIn__c, Timeout__c, & Duration__c & TimeIn__c & TimeOut__c are the Text fields.

I have captured the Time In & Time out , Then format it to HH:MM:SS AM/PM, then stored them in text format in respective field.

 

But Now I need to calculate the duartion(i.e The difference between TimeIn & Time Out). I am unable to findout any ,method for getting the defference between two time..

 

If any body have the solutions, Please let me know..

 

I need help

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

 

Hi,

Before calculating the difference between into time you have to convert into minutes

For example:

In time 10:55

And out time 18:45

Convert both times into minutes

10*60+55 =655

18*60+45=1125

1125-655=460

460/60=7.6 hours

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

 

 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

Hi,

Before calculating the difference between into time you have to convert into minutes

For example:

In time 10:55

And out time 18:45

Convert both times into minutes

10*60+55 =655

18*60+45=1125

1125-655=460

460/60=7.6 hours

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

 

 

This was selected as the best answer
DipakDipak

Thanks for your replay,

 

according  to your suggestion i have split these TimeIn & Time Out text value by ':' separtor , then after getting the HH, MM., SS part, I have converted them to Integer, & Calculated the reuired total hour part, like

 

10*60+55 =655

18*60+45=1125

1125-655=460

but the

 when i am diving 460/60, it results only 7 not 7.6. So please let me know how to get exact decimal value by dividing a integer with a number..

 

Thnks in advance

DipakDipak

Hi, 

 

According to your logic, i have found one issue with it.i.e

 Time In:23:59:55 PM

 Time Out:00:00:04 AM

 

   Duration(in Minutes) =-1,439.8500 minute

 

Just take a look Duration is not correct. I need you help..

Hope you will reply with a proper suggestion.....

 

Awaiting for your response