+ Start a Discussion
GOAL_KEEPERGOAL_KEEPER 

How to calculate seconds from 2 dates?

Hi how do i get the seconds like 0-60 (so counting and resetting) from something like Now()-CreatedDate?

Best Answer chosen by Admin (Salesforce Developers) 
Shannon HaleShannon Hale

Since NOW() - CreatedDate returns a value in days, you can multiply by the number of hours in a day, minutes in an hour, and seconds in a minute to get the total number of seconds:

 

( NOW() - CreatedDate ) * 24 * 60 * 60

 

It sounds like you're looking for a value between 0-60, so just the number of seconds that are not accounted for by minutes? In that case you can use MOD() along with the previous value to determine how many seconds are left over after dividing by 60 seconds:

 

MOD( ( ( Time2__c - Time1__c ) * 24 * 60 * 60 ), 60 )