<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculate difference between start date and end date in a custom object in Data Hub</title>
    <link>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/777430#M1391</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101262"&gt;@MiaSrebrnjak&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/192704"&gt;@ankitparmar09&lt;/a&gt;&amp;nbsp;- I wanted to share that I came up with a solution and it works quite well to what I need.&lt;BR /&gt;&lt;BR /&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
  "name": "duration_days",
  "label": "Duration Days",
  "type": "number",
  "fieldType": "calculation_equation",
  "groupName": "pipeline_milestones",
  "calculationFormula": "if end_date-start_date=0 then 1 else (end_date-start_date)/86400000"
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This field then shows up just calculating the difference in days, and we're all set to report on it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Apr 2023 15:19:44 GMT</pubDate>
    <dc:creator>Shuler</dc:creator>
    <dc:date>2023-04-03T15:19:44Z</dc:date>
    <item>
      <title>Calculate difference between start date and end date in a custom object</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/776913#M1388</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help into this would be greatly appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 21:09:22 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/776913#M1388</guid>
      <dc:creator>Shuler</dc:creator>
      <dc:date>2023-03-31T21:09:22Z</dc:date>
    </item>
    <item>
      <title>Betreff: Calculate difference between start date and end date in a custom object</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/777326#M1389</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/540694"&gt;@Shuler&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reaching out to the Community!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wanted to tag in a couple of subject matter experts to see if they have any input on this matter:&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/268959"&gt;@deepikaverma&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/138768"&gt;@GreyHamilton&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/491153"&gt;@GCasali&lt;/a&gt;,&amp;nbsp;do you have any advice for&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/540694"&gt;@Shuler&lt;/a&gt;? Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers&lt;BR /&gt;Mia, Community Team&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 12:28:23 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/777326#M1389</guid>
      <dc:creator>MiaSrebrnjak</dc:creator>
      <dc:date>2023-04-03T12:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between start date and end date in a custom object</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/777402#M1390</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/540694"&gt;@Shuler&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks for reaching out. You can use the code, it can help you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{# Date Format Code #}&lt;BR /&gt;{% set date = event.event_end_date %}&lt;BR /&gt;{% set dateArr = date|split("/", 1000) %}&lt;BR /&gt;{% set useDate = [&lt;BR /&gt;(dateArr[2]|int + 2000),&lt;BR /&gt;(dateArr[0]|length == 1 ? '0' + dateArr[0] : dateArr[0]),&lt;BR /&gt;(dateArr[1]|length == 1 ? '0' + dateArr[1] : dateArr[1])&lt;BR /&gt;]&lt;BR /&gt;%}&lt;BR /&gt;&lt;BR /&gt;{% set enddate = (useDate[0] + "-" + useDate[1] + "-" + useDate[2] + "T14:31:30+0530")|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp %}&lt;BR /&gt;&lt;BR /&gt;{% set today = (local_dt|unixtimestamp) %}&lt;BR /&gt;&lt;BR /&gt;{% if (enddate &amp;lt;= today ) %}&lt;BR /&gt;&lt;BR /&gt;// Code here&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;{% endif %}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 14:18:53 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/777402#M1390</guid>
      <dc:creator>ankitparmar09</dc:creator>
      <dc:date>2023-04-03T14:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between start date and end date in a custom object</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/777430#M1391</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101262"&gt;@MiaSrebrnjak&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/192704"&gt;@ankitparmar09&lt;/a&gt;&amp;nbsp;- I wanted to share that I came up with a solution and it works quite well to what I need.&lt;BR /&gt;&lt;BR /&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
  "name": "duration_days",
  "label": "Duration Days",
  "type": "number",
  "fieldType": "calculation_equation",
  "groupName": "pipeline_milestones",
  "calculationFormula": "if end_date-start_date=0 then 1 else (end_date-start_date)/86400000"
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This field then shows up just calculating the difference in days, and we're all set to report on it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 15:19:44 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/777430#M1391</guid>
      <dc:creator>Shuler</dc:creator>
      <dc:date>2023-04-03T15:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between start date and end date in a custom object</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/777600#M1393</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/540694"&gt;@Shuler&lt;/a&gt;&amp;nbsp;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.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GreyHamilton_0-1680554288647.png" style="width: 745px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/88620i75C9B1B158B83F0E/image-dimensions/745x417?v=v2" width="745" height="417" role="button" title="GreyHamilton_0-1680554288647.png" alt="GreyHamilton_0-1680554288647.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GreyHamilton_1-1680554634513.png" style="width: 678px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/88621i5122FA1247300BFA/image-dimensions/678x144?v=v2" width="678" height="144" role="button" title="GreyHamilton_1-1680554634513.png" alt="GreyHamilton_1-1680554634513.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 20:48:58 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/777600#M1393</guid>
      <dc:creator>GreyHamilton</dc:creator>
      <dc:date>2023-04-03T20:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between start date and end date in a custom object</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/777739#M1394</link>
      <description>&lt;P&gt;That's great, thank you for sharing&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/540694"&gt;@Shuler&lt;/a&gt;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And thank you for your help&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/138768"&gt;@GreyHamilton&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/192704"&gt;@ankitparmar09&lt;/a&gt;, we really appreciate it!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":yellow_heart:"&gt;💛&lt;/span&gt; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 09:20:51 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Calculate-difference-between-start-date-and-end-date-in-a-custom/m-p/777739#M1394</guid>
      <dc:creator>MiaSrebrnjak</dc:creator>
      <dc:date>2023-04-04T09:20:51Z</dc:date>
    </item>
  </channel>
</rss>

