<?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 calculate the days between 2 dates in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/calculate-the-days-between-2-dates/m-p/217260#M63818</link>
    <description>&lt;P&gt;this is my search: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=2 | 
eval start=relative_time(now(),"@d") | 
eval start_string=strftime(start,"%Y-%m-%d") | 
eval end=strptime("1 jan 2017","%d %b %Y") | 
eval end_string=strftime(end,"%Y-%m-%d") | 
eval start_minus_end=end-start/1400
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;give s me the following: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time   end end_string  start   start_minus_end start_string
1   2016-04-20 10:13:02 1483182000.000000   2017-01-01  1461067200.000000   1482138380.571429   2016-04-20
2   2016-04-20 10:13:02 1483182000.000000   2017-01-01  1461067200.000000   1482138380.571429   2016-04-20
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How do I work out how many days are between &lt;CODE&gt;start_string&lt;/CODE&gt; and &lt;CODE&gt;end_string&lt;/CODE&gt;? &lt;BR /&gt;
I have tried to do this with &lt;CODE&gt;eval start_minus_end=end-start/1400&lt;/CODE&gt; but i am not sure what value &lt;CODE&gt;start_string&lt;/CODE&gt; is? is it milliseconds?&lt;/P&gt;

&lt;P&gt;As an aside I would then like to store this value in a variable that I can somehow use in  the &lt;CODE&gt;predict&lt;/CODE&gt; &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.7/SearchReference/Predict"&gt;function&lt;/A&gt; and assign it to &lt;CODE&gt;future_timespan&lt;/CODE&gt;  e.g. &lt;CODE&gt;predict  kpi1 as kpi1 future_timespan=&amp;lt;VARIABLE&amp;gt; holdback=1&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Apr 2016 22:23:59 GMT</pubDate>
    <dc:creator>HattrickNZ</dc:creator>
    <dc:date>2016-04-19T22:23:59Z</dc:date>
    <item>
      <title>calculate the days between 2 dates</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-the-days-between-2-dates/m-p/217260#M63818</link>
      <description>&lt;P&gt;this is my search: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=2 | 
eval start=relative_time(now(),"@d") | 
eval start_string=strftime(start,"%Y-%m-%d") | 
eval end=strptime("1 jan 2017","%d %b %Y") | 
eval end_string=strftime(end,"%Y-%m-%d") | 
eval start_minus_end=end-start/1400
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;give s me the following: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time   end end_string  start   start_minus_end start_string
1   2016-04-20 10:13:02 1483182000.000000   2017-01-01  1461067200.000000   1482138380.571429   2016-04-20
2   2016-04-20 10:13:02 1483182000.000000   2017-01-01  1461067200.000000   1482138380.571429   2016-04-20
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How do I work out how many days are between &lt;CODE&gt;start_string&lt;/CODE&gt; and &lt;CODE&gt;end_string&lt;/CODE&gt;? &lt;BR /&gt;
I have tried to do this with &lt;CODE&gt;eval start_minus_end=end-start/1400&lt;/CODE&gt; but i am not sure what value &lt;CODE&gt;start_string&lt;/CODE&gt; is? is it milliseconds?&lt;/P&gt;

&lt;P&gt;As an aside I would then like to store this value in a variable that I can somehow use in  the &lt;CODE&gt;predict&lt;/CODE&gt; &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.7/SearchReference/Predict"&gt;function&lt;/A&gt; and assign it to &lt;CODE&gt;future_timespan&lt;/CODE&gt;  e.g. &lt;CODE&gt;predict  kpi1 as kpi1 future_timespan=&amp;lt;VARIABLE&amp;gt; holdback=1&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 22:23:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-the-days-between-2-dates/m-p/217260#M63818</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2016-04-19T22:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the days between 2 dates</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-the-days-between-2-dates/m-p/217261#M63819</link>
      <description>&lt;P&gt;Hi HattrickNZ,&lt;/P&gt;

&lt;P&gt;epoch is time in seconds so replace the last eval with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; eval start_minus_end=round((end-start)/86400,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and you will get the numbers of days.&lt;BR /&gt;
This is the result:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/1276i5770F5A6F06C667A/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;BR /&gt;
Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 22:34:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-the-days-between-2-dates/m-p/217261#M63819</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2016-04-19T22:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the days between 2 dates</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-the-days-between-2-dates/m-p/217262#M63820</link>
      <description>&lt;P&gt;Splunk also has a tostring function that allows you to, among other things, convert seconds to a duration.  The result is in the format of days+HH:MM:SS&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval duration = tostring(end - start,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So in your case the result for today is 257+01:00:00.000000&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 23:09:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-the-days-between-2-dates/m-p/217262#M63820</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2016-04-19T23:09:32Z</dc:date>
    </item>
  </channel>
</rss>

