APIs & Integrations

S_Tasneem
Member

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 

S_Tasneem_0-1662619255420.png

Try2: I tried changing the code to:

var create_date = new Date(event.inputFields['createdate'])

but the value returned is

S_Tasneem_1-1662619390735.png

Any suggestions would be greatly helpful.

 

Thankyou!

 

0 Upvotes
1 Accepted solution
LMeert
Solution
Guide | Platinum Partner
Guide | Platinum Partner

Get number of days between createdate & closedate of a deal

SOLVE

Hi @S_Tasneem,

 

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)));

 

LMeert_0-1663057662524.png

 

Hope this helps !
If it does, please consider marking this answer as a solution 🙂

 

Best,

Ludwig

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

View solution in original post

0 Upvotes
3 Replies 3
Thrive
Contributor | Elite Partner
Contributor | Elite Partner

Get number of days between createdate & closedate of a deal

SOLVE

Hi there, we have built an app for the marketplace that allows you to automatically calculate the time between 2 dates. Feel free to check it out here: https://ecosystem.hubspot.com/marketplace/apps/marketing/data-management/calculations-3449553

0 Upvotes
LMeert
Solution
Guide | Platinum Partner
Guide | Platinum Partner

Get number of days between createdate & closedate of a deal

SOLVE

Hi @S_Tasneem,

 

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)));

 

LMeert_0-1663057662524.png

 

Hope this helps !
If it does, please consider marking this answer as a solution 🙂

 

Best,

Ludwig

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

Get number of days between createdate & closedate of a deal

SOLVE

Hi, @S_Tasneem 👋 Let's see if we can get the converstaion going with some of our community experts.

Hey @Teun @LMeert @mangelet, do you have any insight you can offer to @S_Tasneem?

 

Thank you! — Jaycee

 

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot