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
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12 

How to calculate the Inbetween the "End Date and Time" and "Start Date and Time".

Hi,

I have a two date field "Start Date and time" and "End date and time" How  to auto populate based on the difference between the "End Date and Time" and the "Start Date and Time"  value populate to another one field? Kindly give any idea or give any example  code

Thanks
Best Answer chosen by sundhar.mks1.3962649227519546E12
Anoop yadavAnoop yadav
Hi,
Create a formula field Like below.
(End Date and Time - Start Date and Time)
it will return you number of days.

Check the below link for more information.
https://help.salesforce.com/apex/HTViewHelpDoc?id=formula_using_date_datetime.htm&language=en_US (https://help.salesforce.com/apex/HTViewHelpDoc?id=formula_using_date_datetime.htm&language=en_US)

All Answers

Anoop yadavAnoop yadav
Hi,
Create a formula field Like below.
(End Date and Time - Start Date and Time)
it will return you number of days.

Check the below link for more information.
https://help.salesforce.com/apex/HTViewHelpDoc?id=formula_using_date_datetime.htm&language=en_US (https://help.salesforce.com/apex/HTViewHelpDoc?id=formula_using_date_datetime.htm&language=en_US)
This was selected as the best answer
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12
Hi Anoop Yadav,

I have created formula field using following code. Two Date inbetween day/hour/minits populated to Job Time field

TEXT(FLOOR(End_Date_and_Time__c-Start_Date_and_Time__c)) & " Day(s), " & TEXT( FLOOR( MOD( (End_Date_and_Time__c-Start_Date_and_Time__c) * 24, 24 ) ) ) & " Hour(s) and " & TEXT( ROUND( MOD( (End_Date_and_Time__c-Start_Date_and_Time__c) * 24 * 60, 60 ), 0 ) ) & " Minute(s)"

Result:
Start Date and Time: 12/26/2014 3:31 AM
End Date and Time :  12/28/2014 3:37 AM
Job Time:  2 Day(s), 0 Hour(s) and 2 Minute(s)

Now Day(s)/Hour(s)/Minit(s) only update to another one field  of "Time" I want to update the value separately like this. 
Job Time: 2
Time: Day(s)
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12
Hi Anoop Yadav,

How to achive this requirement  to Trigger,Kindly give any example

Thanks.