<?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 the date in my search? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-the-date-in-my-search/m-p/435628#M169092</link>
    <description>&lt;P&gt;adding to the comments and nice answer above by @jconger,&lt;BR /&gt;
below is a sample search to run anywhere. i added a field &lt;CODE&gt;some_id&lt;/CODE&gt; that you can group your query by. for example if there is a transaction id or something of that sort. th efirst 6 lines are generating data, the rest is the solution&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count =1 
| eval field = "some_id"
| eval data = "End_Time=2018-06-04-10.45.09,Start_Time=2018-06-04-10.45.00"
| makemv delim="," data
| mvexpand data
| rex field=data "(?&amp;lt;time_field&amp;gt;\S+)\=(?&amp;lt;time_value&amp;gt;\S+)"
| eval time_in_epoch = strptime(time_value, "%Y-%m-%d-%H.%M.%S")
| eval end_time_epoch = if(time_field="End_Time",time_in_epoch,null())
| eval start_time_epoch = if(time_field="Start_Time",time_in_epoch,null())
| stats values(*_time_epoch) as *_time_epoch by field
| eval diff_in_sec = round(end_time_epoch - start_time_epoch, 0)
| eval diff_human=tostring(diff_in_sec, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;see screenshot below:&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/5116i5193255D341CFDE5/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
    <pubDate>Mon, 04 Jun 2018 16:38:51 GMT</pubDate>
    <dc:creator>adonio</dc:creator>
    <dc:date>2018-06-04T16:38:51Z</dc:date>
    <item>
      <title>How to subtract the date in my search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-the-date-in-my-search/m-p/435625#M169089</link>
      <description>&lt;P&gt;How to subtract the below date?&lt;/P&gt;

&lt;P&gt;End Time is       2018-06-04-10.45.09&lt;BR /&gt;
Start Time is    2018-06-04-10.45.00 &lt;/P&gt;

&lt;P&gt;End Time - Start Time&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 16:01:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-the-date-in-my-search/m-p/435625#M169089</guid>
      <dc:creator>abhi04</dc:creator>
      <dc:date>2018-06-04T16:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract the date in my search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-the-date-in-my-search/m-p/435626#M169090</link>
      <description>&lt;P&gt;You could convert to epoch and subtract. Try something like: &lt;CODE&gt;| eval epoch1=strptime(endTime,"%Y-%m-%d-%H.%M.%S") | eval epoch2=strptime(startTime,"%Y-%m-%d-%H.%M.%S") | eval timediff=epoch1-epoch2&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;This gives you the difference in seconds. You can convert as needed.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 16:20:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-the-date-in-my-search/m-p/435626#M169090</guid>
      <dc:creator>mdsnmss</dc:creator>
      <dc:date>2018-06-04T16:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract the date in my search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-the-date-in-my-search/m-p/435627#M169091</link>
      <description>&lt;P&gt;What do you want as the difference?  If it is just a number of seconds between the two, the following will work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval End_Time="2018-06-04-10.45.09" | eval Start_Time="2018-06-04-10.45.00" | convert timeformat="%Y-%m-%d-%H.%M.%S" mktime(End_Time) AS EndTime  mktime(Start_Time) AS StartTime | eval diff = EndTime - StartTime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Jun 2018 16:22:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-the-date-in-my-search/m-p/435627#M169091</guid>
      <dc:creator>jconger</dc:creator>
      <dc:date>2018-06-04T16:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract the date in my search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-the-date-in-my-search/m-p/435628#M169092</link>
      <description>&lt;P&gt;adding to the comments and nice answer above by @jconger,&lt;BR /&gt;
below is a sample search to run anywhere. i added a field &lt;CODE&gt;some_id&lt;/CODE&gt; that you can group your query by. for example if there is a transaction id or something of that sort. th efirst 6 lines are generating data, the rest is the solution&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count =1 
| eval field = "some_id"
| eval data = "End_Time=2018-06-04-10.45.09,Start_Time=2018-06-04-10.45.00"
| makemv delim="," data
| mvexpand data
| rex field=data "(?&amp;lt;time_field&amp;gt;\S+)\=(?&amp;lt;time_value&amp;gt;\S+)"
| eval time_in_epoch = strptime(time_value, "%Y-%m-%d-%H.%M.%S")
| eval end_time_epoch = if(time_field="End_Time",time_in_epoch,null())
| eval start_time_epoch = if(time_field="Start_Time",time_in_epoch,null())
| stats values(*_time_epoch) as *_time_epoch by field
| eval diff_in_sec = round(end_time_epoch - start_time_epoch, 0)
| eval diff_human=tostring(diff_in_sec, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;see screenshot below:&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/5116i5193255D341CFDE5/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 16:38:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-the-date-in-my-search/m-p/435628#M169092</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2018-06-04T16:38:51Z</dc:date>
    </item>
  </channel>
</rss>

