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 .

  • Can you add what you have tried so far? Are you trying to do this in a formula? In Apex?
    – Adrian Larson
    Dec 17, 2015 at 18:09

2 Answers 2


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)


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)
  • I am Trying to do this in a formula. So the addSeconds Method wouldn't be an option. Yes the "Service Duration" is listed in seconds but the "data type" is number Thanks for the reply. Dec 17, 2015 at 18:20

You can use the addSeconds method in the DateTime class (I'm assuming your Service Duration is listed in seconds).

It works like this:

DateTime myDateTime = DateTime.newInstance(2015, 12, 21, 14, 0, 0);
DateTime newDateTime = myDateTime.addSeconds(3600); //Service Duration

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .