Get number of days between createdate & closedate of a deal
SOLVE
Hello,
My requirement is to get the number of days-difference between cretedate & closedate of a deal. The number of days between these two dates should be populated in a third-party application form, So I am doing the development in a deal-based workflow. But I am not able to get the correct date format of the two dates, So I am not able to get the days-difference.
Try1: I have passed this line of code in workflow:
var create_date = event.inputFields['createdate']
but the value returned is
Try2: I tried changing the code to:
var create_date = new Date(event.inputFields['createdate'])
On the first try you do get a timestamp, you simply have to substract both timestamps (create date - today or vice versa) and convert the result back in days.
A timestamp is usually in milliseconds, so to get the number of days you could use this simple formula :
result_in_days = result_in_ms/1000/60/60/24 and truncate that to the day.
Here's a working snippet I've just tested :
var date = event.inputFields['createdate'];
var future_date = Date.now();
var days_difference = Math.abs(Math.trunc((future_date - date)/(1000*3600*24)));
Hope this helps ! If it does, please consider marking this answer as a solution 🙂
Best,
Ludwig
CTO @ Mi4 Hubspot Platinum Partner and Integration Expert
Passionate human, very curious about everything data and automation.
On the first try you do get a timestamp, you simply have to substract both timestamps (create date - today or vice versa) and convert the result back in days.
A timestamp is usually in milliseconds, so to get the number of days you could use this simple formula :
result_in_days = result_in_ms/1000/60/60/24 and truncate that to the day.
Here's a working snippet I've just tested :
var date = event.inputFields['createdate'];
var future_date = Date.now();
var days_difference = Math.abs(Math.trunc((future_date - date)/(1000*3600*24)));
Hope this helps ! If it does, please consider marking this answer as a solution 🙂
Best,
Ludwig
CTO @ Mi4 Hubspot Platinum Partner and Integration Expert
Passionate human, very curious about everything data and automation.