Calculate difference between start date and end date in a custom object
SOLVE
I have created a custom object in HubSpot, which has a start and end date - the calculated field can check for the time between however we run into an issue where if it's the same day, we get a 0 value when we would want to see a 1 value.
I've tried to do some custom code via a workflow to calculate this, but I am not a programmer and have no idea how to get something like this to work. What I am trying to do is if the start date and end day is the same, make the field say 1, if they are not the same dates, then calculate the difference.
Calculate difference between start date and end date in a custom object
SOLVE
Thanks @MiaSrebrnjak and @ankitparmar09 - I wanted to share that I came up with a solution and it works quite well to what I need.
Via the API, I created a calculation field with an if then condition. It calculates the difference between the times and if they are 0, it will output 1, otherwise I do the calculation, divide it by the miliseconds and get days. It just outputs a number, but this is exaclty what we need and want. Code below:
Calculate difference between start date and end date in a custom object
SOLVE
@Shuler Love this solution. I believe yours is the ideal solution, but for anyone who isn't comfortable with APIs or custom code I figured out a way to do it with a 'Days Between' calculated field and the Format feature in a workflow.
Here is the workflow utilizing the Format function. I tagged this as "Original Duration" as you could have it not re-enroll so it's only set once. Depending on if your dates change, you could potentially benefit from a "snapshot" of the original duration. The round was added because it was adding a 0 decimal point even though the property limited them.
Results:
Did this post help solve your problem? If so, please mark it as a solution.
Grey Hamilton, Sr. Technical Consultant Bayard Bradford Advanced CRM Implementation | HubSpot Custom Integration Services | Datawarehouse.io Apps for HubSpot Elite HubSpot Solutions Partner > Follow me on LinkedIn
Calculate difference between start date and end date in a custom object
SOLVE
Thanks @MiaSrebrnjak and @ankitparmar09 - I wanted to share that I came up with a solution and it works quite well to what I need.
Via the API, I created a calculation field with an if then condition. It calculates the difference between the times and if they are 0, it will output 1, otherwise I do the calculation, divide it by the miliseconds and get days. It just outputs a number, but this is exaclty what we need and want. Code below:
Calculate difference between start date and end date in a custom object
SOLVE
@Shuler Love this solution. I believe yours is the ideal solution, but for anyone who isn't comfortable with APIs or custom code I figured out a way to do it with a 'Days Between' calculated field and the Format feature in a workflow.
Here is the workflow utilizing the Format function. I tagged this as "Original Duration" as you could have it not re-enroll so it's only set once. Depending on if your dates change, you could potentially benefit from a "snapshot" of the original duration. The round was added because it was adding a 0 decimal point even though the property limited them.
Results:
Did this post help solve your problem? If so, please mark it as a solution.
Grey Hamilton, Sr. Technical Consultant Bayard Bradford Advanced CRM Implementation | HubSpot Custom Integration Services | Datawarehouse.io Apps for HubSpot Elite HubSpot Solutions Partner > Follow me on LinkedIn