<?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: Difference between two string date fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418147#M120264</link>
    <description>&lt;P&gt;I've one file CSV. In this file i have some fields, two of this are date. Splunk read this date like a strings. Now, i have need to calcolate the difference between this two dates, row-by-row. My final output must be a new column with all difference of this dates in days. i wrote 183 days, but was an example. I want all difference, for any row and any dates, in day, only this.&lt;/P&gt;

&lt;P&gt;I try to write this:&lt;BR /&gt;
...&lt;BR /&gt;
 | eval start_epoch = strptime(StardDate, "%d/%m/%Y")&lt;BR /&gt;
 | eval end_epoch = strptime(EndDate, "%d/%m/%Y")&lt;BR /&gt;
 | eval gap_in_seconds = end_epoch - start_epoch&lt;BR /&gt;
 | eval gap_in_days = round(gap_in_seconds / 86400)&lt;BR /&gt;
and my output is null. Splunk don't convert my string date in strptime, if i try to write only " eval start_epoch = strptime(StardDate, "%d/%m/%Y")" i don't see anythings, i don't have output.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 00:11:08 GMT</pubDate>
    <dc:creator>perryd</dc:creator>
    <dc:date>2020-09-30T00:11:08Z</dc:date>
    <item>
      <title>Difference between two string date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418142#M120259</link>
      <description>&lt;P&gt;Hi, i searched but i don't found any solution. I wont the difference between two fields that are date in string format. My field are:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;StartDate: String-&amp;gt;dd/mm/yyyy;&lt;/LI&gt;
&lt;LI&gt;EndDate: String-&amp;gt; dd/mm/yyyy;
Its possible obtain the difference in days? For example:
in first row, i've 01/01/2017 and 01/07/2017. My result must be 183.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;I don't understand how to convert my string date in values day.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 09:20:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418142#M120259</guid>
      <dc:creator>perryd</dc:creator>
      <dc:date>2019-04-17T09:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two string date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418143#M120260</link>
      <description>&lt;P&gt;hello there,&lt;/P&gt;

&lt;P&gt;run this search anywhere and apply the logic to address your challenge.&lt;BR /&gt;
here i used &lt;CODE&gt;eval&lt;/CODE&gt; &lt;CODE&gt;strptime&lt;/CODE&gt; and leverage the epoch numeric value to calculate gap&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1
| eval start_date = "01/01/2017"
| eval end_date="01/07/2017"
| rename COMMENT as "above creates fake data, below is your solution" 
| eval start_epoch = strptime(start_date, "%d/%m/%Y")
| eval end_epoch = strptime(end_date, "%d/%m/%Y")
| eval gap_in_seconds = end_epoch - start_epoch
| eval gap_in_days = round(gap_in_seconds / 86400)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;further reading:&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.5/SearchReference/Commontimeformatvariables"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.5/SearchReference/Commontimeformatvariables&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 09:33:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418143#M120260</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-04-17T09:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two string date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418144#M120261</link>
      <description>&lt;P&gt;@perryd &lt;/P&gt;

&lt;P&gt;The difference between these two dates is &lt;CODE&gt;181&lt;/CODE&gt;. And if you want to add last day also in your count then  add &lt;CODE&gt;1&lt;/CODE&gt;  in your search. Is that any specific calculation for getting &lt;CODE&gt;183&lt;/CODE&gt;?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval start_date="01/01/2017",end_date="01/07/2017" 
| eval dates=mvcount(mvrange(strptime(start_date,"%d/%m/%Y"),strptime(end_date,"%d/%m/%Y"),86400))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;| eval dates=dates+1&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 09:43:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418144#M120261</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-04-17T09:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two string date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418145#M120262</link>
      <description>&lt;P&gt;Hi, don't work. Specifically, when i use the function strptime(StardDate) or strptime(EndDate) i lost all data in these fields. Splunk don't convert my string in strptime, so, When i try to do difference between startdate and enddate i don't have any output.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 10:06:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418145#M120262</guid>
      <dc:creator>perryd</dc:creator>
      <dc:date>2019-04-17T10:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two string date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418146#M120263</link>
      <description>&lt;P&gt;Can you please share some more information about your events and fields (StardDate, EndDate &amp;amp; others)?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 10:08:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418146#M120263</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-04-17T10:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two string date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418147#M120264</link>
      <description>&lt;P&gt;I've one file CSV. In this file i have some fields, two of this are date. Splunk read this date like a strings. Now, i have need to calcolate the difference between this two dates, row-by-row. My final output must be a new column with all difference of this dates in days. i wrote 183 days, but was an example. I want all difference, for any row and any dates, in day, only this.&lt;/P&gt;

&lt;P&gt;I try to write this:&lt;BR /&gt;
...&lt;BR /&gt;
 | eval start_epoch = strptime(StardDate, "%d/%m/%Y")&lt;BR /&gt;
 | eval end_epoch = strptime(EndDate, "%d/%m/%Y")&lt;BR /&gt;
 | eval gap_in_seconds = end_epoch - start_epoch&lt;BR /&gt;
 | eval gap_in_days = round(gap_in_seconds / 86400)&lt;BR /&gt;
and my output is null. Splunk don't convert my string date in strptime, if i try to write only " eval start_epoch = strptime(StardDate, "%d/%m/%Y")" i don't see anythings, i don't have output.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:11:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418147#M120264</guid>
      <dc:creator>perryd</dc:creator>
      <dc:date>2020-09-30T00:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two string date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418148#M120265</link>
      <description>&lt;P&gt;@perryd&lt;/P&gt;

&lt;P&gt;I have tried with below CSV content. It's working. Is that any space OR double quotes in your CSV content?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;StardDate,EndDate
01/01/2017,01/07/2017
01/01/2017,01/08/2017
01/01/2017,01/09/2017
01/01/2017,01/10/2017
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Apr 2019 11:45:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418148#M120265</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-04-17T11:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two string date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418149#M120266</link>
      <description>&lt;P&gt;Can i see how work on your splunk? It make the difference between these dates? (in day). Because my CVS is not controllable from me, i can't modify it. I can try to upload a my file with some dates and do test for it.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 11:55:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418149#M120266</guid>
      <dc:creator>perryd</dc:creator>
      <dc:date>2019-04-17T11:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two string date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418150#M120267</link>
      <description>&lt;P&gt;You can share your CSV data here OR data from search, using &lt;CODE&gt;| inputlookup&lt;/CODE&gt;. So we can look at that.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 12:04:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418150#M120267</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-04-17T12:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two string date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418151#M120268</link>
      <description>&lt;P&gt;I've data protect from non disclosure agreement. Now i try with a my CSV test and i see if run. If i continue to have problem i ask here, thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 12:09:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418151#M120268</guid>
      <dc:creator>perryd</dc:creator>
      <dc:date>2019-04-17T12:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two string date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418152#M120269</link>
      <description>&lt;P&gt;Glad to help you.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Happy Splunking&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 12:11:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418152#M120269</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-04-17T12:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two string date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418153#M120270</link>
      <description>&lt;P&gt;HI Perry are your dates in 01/01/2017 format or 01-01-2017 format coz that will change the time format we are giving in order to convert the epoch strings.&lt;/P&gt;

&lt;P&gt;SO the strptime &lt;BR /&gt;
 &lt;STRONG&gt;eval start_epoch = strptime(StardDate, "%d/%m/%Y")&lt;BR /&gt;
will become &lt;BR /&gt;
 eval start_epoch = strptime(StardDate, "%d-%m-%Y")&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I was making the same mistake &lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:53:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-two-string-date-fields/m-p/418153#M120270</guid>
      <dc:creator>beingkaran</dc:creator>
      <dc:date>2020-09-30T03:53:20Z</dc:date>
    </item>
  </channel>
</rss>

