+ Start a Discussion
m pandeym pandey 

how to calculate the time duration hors...?

sttime 5:00 AM
ettime 6:00 PM

sttime in text frmt
ettime in text frmt

i want the total hours in time between..
vishnu Rvishnu R
hi gopal,

take two date/time  fields

>>> (( shobithapp__End_Date__c - shobithapp__Start_Date__c) *24) == this formula will give you total no of Hours between two date/time.
>>> (( shobithapp__End_Date__c - shobithapp__Start_Date__c )*24*60)== this formula will give you total number of minutes between two date/time.

hope this helps you..mark it as best answer if this resolved your issue..

Nayana KNayana K
String sttime = '5:00 AM';
String ettime = '6:00 PM';
String stAMOrPM, etAMOrPM;
Integer stHrs, etHrs, hrDiff;
List<String> stParts, etParts;
stAMOrPM = sttime.right(2);
etAMOrPM = ettime.right(2);
stParts = sttime.split(':');
stHrs = Integer.valueOf(stParts[0]);
etParts = ettime.split(':');
etHrs = Integer.valueOf(etParts[0]);

if(stAMOrPM == 'PM')
    stHrs += 12;
if(etAMOrPM == 'PM')
    etHrs += 12;
hrDiff = etHrs - stHrs;

/*Eg: if sttime = '5:00 AM' and ettime = '4:00 AM', then it is considered from
today's 5am to tomorrows 4am so 23hrs difference*/
if(hrDiff < 0)
    hrDiff += 24;
system.debug('==hrDiff=' + hrDiff);

I tried this in dev console, it is giving expected result.