<?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: How to subtract one date from another? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335452#M99644</link>
    <description>&lt;P&gt;@eranday, please try the following runanywhere search, &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval date2=relative_time(_time,"-3d")
| eval date1=strftime(_time,"%Y%m%d")
| eval date2=strftime(date2,"%Y%m%d")
| eval diff=date1-date2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can replace first two pipes with your query to get date1 and date2 as epoch time. I have used &lt;CODE&gt;relative_time&lt;/CODE&gt; function to get dummy data which is 3 days prior i.e. &lt;CODE&gt;-3d&lt;/CODE&gt;.&lt;/P&gt;</description>
    <pubDate>Mon, 11 Dec 2017 10:39:55 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-12-11T10:39:55Z</dc:date>
    <item>
      <title>How to subtract one date from another?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335450#M99642</link>
      <description>&lt;P&gt;I hold a list of two dates that I want to subtract one from another&lt;BR /&gt;
these dates are an outcome from: &lt;BR /&gt;
          |convert timeformat="%Y-%m-%d" ctime(_time) AS date1&lt;/P&gt;

&lt;P&gt;source:&lt;BR /&gt;
|      date1     |      date2      |&lt;BR /&gt;
|2017-12-08 | 2017-12-05 |&lt;BR /&gt;
|2017-12-04 | 2017-12-05 |&lt;BR /&gt;
|2017-12-05 | 2017-12-05 |&lt;/P&gt;

&lt;P&gt;Wanted outcom:&lt;BR /&gt;
|      date 1    |      date 2     |  diff |&lt;BR /&gt;
|2017-12-08 | 2017-12-05 |   3    |&lt;BR /&gt;
|2017-12-04 | 2017-12-05 |   1    |&lt;BR /&gt;
|2017-12-05 | 2017-12-05 |   0    |&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 10:10:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335450#M99642</guid>
      <dc:creator>eranday</dc:creator>
      <dc:date>2017-12-11T10:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract one date from another?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335451#M99643</link>
      <description>&lt;P&gt;Hi @eranday,&lt;/P&gt;

&lt;P&gt;Can you please try this search?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH
| eval dates=mvrange(strptime(date2,"%Y-%m-%d"),strptime(date1,"%Y-%m-%d"),86400)
| eval diff=mvcount(dates)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My Sample Search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval date1="2017-12-08" , date2="2017-12-05" 
| eval dates=mvrange(strptime(date2,"%Y-%m-%d"),strptime(date1,"%Y-%m-%d"),86400)
| eval diff=mvcount(dates)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 10:25:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335451#M99643</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-12-11T10:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract one date from another?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335452#M99644</link>
      <description>&lt;P&gt;@eranday, please try the following runanywhere search, &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval date2=relative_time(_time,"-3d")
| eval date1=strftime(_time,"%Y%m%d")
| eval date2=strftime(date2,"%Y%m%d")
| eval diff=date1-date2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can replace first two pipes with your query to get date1 and date2 as epoch time. I have used &lt;CODE&gt;relative_time&lt;/CODE&gt; function to get dummy data which is 3 days prior i.e. &lt;CODE&gt;-3d&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 10:39:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335452#M99644</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-11T10:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract one date from another?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335453#M99645</link>
      <description>&lt;P&gt;not working&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 10:41:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335453#M99645</guid>
      <dc:creator>eranday</dc:creator>
      <dc:date>2017-12-11T10:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract one date from another?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335454#M99646</link>
      <description>&lt;P&gt;search updated pls try it.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 11:26:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335454#M99646</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-12-11T11:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract one date from another?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335455#M99647</link>
      <description>&lt;P&gt;@eranday&lt;/P&gt;

&lt;P&gt;Please try below,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval d1="2017-12-08" | eval d2="2017-12-05" | eval da1=strptime(d1,"%Y-%m-%d") | eval da2=strptime(d2,"%Y-%m-%d") | eval diff=da1-da2 | eval diff=strftime(diff,"%d")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Dec 2017 15:10:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335455#M99647</guid>
      <dc:creator>sbbadri</dc:creator>
      <dc:date>2017-12-11T15:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract one date from another?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335456#M99648</link>
      <description>&lt;P&gt;Champ!! it works&lt;BR /&gt;
Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 09:58:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335456#M99648</guid>
      <dc:creator>eranday</dc:creator>
      <dc:date>2017-12-12T09:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract one date from another?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335457#M99649</link>
      <description>&lt;P&gt;Great.. !!&lt;/P&gt;

&lt;P&gt;Can you please accept the answer to close this question?&lt;/P&gt;

&lt;P&gt;Thanks&lt;BR /&gt;
Happy Splunking&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 10:10:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-one-date-from-another/m-p/335457#M99649</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-12-12T10:10:13Z</dc:date>
    </item>
  </channel>
</rss>

