[SalesForce] How To Increment Datetime by Decimal

I have a packaged application installed in my salesforce which sends the Service Duration (Number Data Type) = 3,600.00 and another field Scheduled Date Time 12/21/2015 2:00 PM (DateTime Field Type).

I would like to calculate Service Duration + Scheduled Date Time, so I can get the end of the scheduled date time.

I get an error because they are of two different data types; number and Date/time.

How can I convert the number "data type" field to an hr/mins and then add that to the Date field .

Best Answer

When adding a Decimal to a Datetime in a formula, it represents a number of days. If you want to add seconds, you just need to divide by the appropriate value.

Scheduled_Date_Time__c + Service_Duration__c / (24 * 60 * 60)

If the duration were in minutes:

Scheduled_Date_Time__c + Service_Duration__c / (24 * 60)

Hours:

Scheduled_Date_Time__c + Service_Duration__c / 24

You also probably want to protect yourself against a null duration:

Scheduled_Date_Time__c + IF(ISNULL(Service_Duration__c), 0, Service_Duration__c / 24)