You need to sign in to do that
Don't have an account?
Mohan Selvam
Difference between Time
In my Apex Code I have Default Start time and Default End Time named as start and stop, code as follows
time start = time.newInstance(8,30,0,0);
time stop = time.newInstance(17,0,0,0);
and I am getting start time and endtime from Object [field type DateTime] from that i am getting only time in Starttime and Endtime, code as follows
time Starttime = Time.newInstance(SSJ.Start_Date_and_Time__c.hour(),SSJ.Start_Date_and_Time__c.minute(),SSJ.Start_Date_and_Time__c.second(),SSJ.Start_Date_and_Time__c.millisecond());
time Endtime = Time.newInstance(SSJ.End_Date_and_Time__c.hour(),SSJ.End_Date_and_Time__c.minute(),SSJ.End_Date_and_Time__c.second(),SSJ.End_Date_and_Time__c.millisecond());
Now i want to find the difference between
Stop to Starttime and
Start to Endtime . how to calculate this?
Thanks and Regards
S.Mohan
time start = time.newInstance(8,30,0,0);
time stop = time.newInstance(17,0,0,0);
and I am getting start time and endtime from Object [field type DateTime] from that i am getting only time in Starttime and Endtime, code as follows
time Starttime = Time.newInstance(SSJ.Start_Date_and_Time__c.hour(),SSJ.Start_Date_and_Time__c.minute(),SSJ.Start_Date_and_Time__c.second(),SSJ.Start_Date_and_Time__c.millisecond());
time Endtime = Time.newInstance(SSJ.End_Date_and_Time__c.hour(),SSJ.End_Date_and_Time__c.minute(),SSJ.End_Date_and_Time__c.second(),SSJ.End_Date_and_Time__c.millisecond());
Now i want to find the difference between
Stop to Starttime and
Start to Endtime . how to calculate this?
Thanks and Regards
S.Mohan
You can simply compute the difference, expressed in milliseconds, using this code: Now, if you want the resut in a human readable format, have a look at http://stackoverflow.com/questions/175554/how-to-convert-milliseconds-into-human-readable-form.
Hope this helps,
Fred
All Answers
You can simply compute the difference, expressed in milliseconds, using this code: Now, if you want the resut in a human readable format, have a look at http://stackoverflow.com/questions/175554/how-to-convert-milliseconds-into-human-readable-form.
Hope this helps,
Fred
Thank you so much for your valuable reply... it helps me a lot...
Thanks and regards
S.Mohan
Hi Frédéric Trébuchet
I tried the same and i got my result. But if i am entering input start time as 10:30 AM and End time as 17:00 PM so the actual output is 6:30 Hrs but it is returning 6 Hrs. Please tell me what went wrong or what i shouls to the exact hours from milliseconds.
My code as follows,
FirstDiff=(((stop.hour()*3600000)+(stop.minute()*60000)+(stop.second()*1000)+(stop.millisecond()))-
((Starttime .hour()*3600000)+(Starttime .minute()*60000)+(Starttime .second()*1000)+(Starttime .millisecond())))/(1000*60*60);
Declare FirstDiff as a decimal variable because 23400000/(1000*60*60) = 6.5 hours
Don't know what you want to do with the result but remember that presenting hours using decimal values may be confusing (6.5 hours = 6 hours and a half, 6.1 hours = 6 hours and 6 minutes, and so on).
Hope this helps,
Fred
Thanks for your instant reply... I will explain my concepts
Actually i am calculating Techncian Jobtime from Start time to End time.
Start time = 16/01/2015 8:30 am
End time = 16/01/2015 16:30 pm
So
Jobtime = 8:00 hrs
In this method, seconds are computed but not displayed in result. Just add them if needed, else, remove seconds computation.
Calling this method is pretty simple: Hope this is what you are looking for.
Fred
Thank you i will try this and let youknow the result...
Regards
S.Mohan