<?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 two date and time in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/how-to-subtract-two-date-and-time/m-p/384480#M69136</link>
    <description>&lt;P&gt;Try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search with datefield1 and datefield2 which you want to subtract for duration
| eval duration_secs=strptime(datefield2,"%Y-%m-%d %H:%M:%S.%N")-strptime(datefield1,"%Y-%m-%d %H:%M:%S.%N")
| eval duration_str=tostring(duration,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 03 Aug 2018 18:04:47 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-08-03T18:04:47Z</dc:date>
    <item>
      <title>how to subtract two date and time</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/how-to-subtract-two-date-and-time/m-p/384478#M69134</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;

&lt;P&gt;I have two date formats&lt;/P&gt;

&lt;P&gt;i have to subtract to find the time duratiuon.Can anyone help me convert these to epoch time and then subtract&lt;/P&gt;

&lt;P&gt;2018-03-29 10:54:55.0&lt;/P&gt;

&lt;P&gt;Regards&lt;BR /&gt;
Shraddha&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 17:37:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/how-to-subtract-two-date-and-time/m-p/384478#M69134</guid>
      <dc:creator>Mohsin123</dc:creator>
      <dc:date>2018-08-03T17:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to subtract two date and time</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/how-to-subtract-two-date-and-time/m-p/384479#M69135</link>
      <description>&lt;P&gt;Hello there,&lt;/P&gt;

&lt;P&gt;Assuming you have your timestamps as start_date=2018-03-29 10:54:55.0 end_date=2018-04-29 10:54:55.0&lt;/P&gt;

&lt;P&gt;Give this a shot,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_base search 
     | eval start=strptime(start_date, "%Y-%m-%d %H:%M:%S.%N") 
     | eval end=strptime(end_date, "%Y-%m-%d %H:%M:%S.%N") 
     | eval difference = end - start 
     | table difference
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Additionally, have a look at the below links for more details.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Commontimeformatvariables" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Commontimeformatvariables&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Convert" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Convert&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/DateandTimeFunctions" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/DateandTimeFunctions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:43:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/how-to-subtract-two-date-and-time/m-p/384479#M69135</guid>
      <dc:creator>sudosplunk</dc:creator>
      <dc:date>2020-09-29T20:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to subtract two date and time</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/how-to-subtract-two-date-and-time/m-p/384480#M69136</link>
      <description>&lt;P&gt;Try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search with datefield1 and datefield2 which you want to subtract for duration
| eval duration_secs=strptime(datefield2,"%Y-%m-%d %H:%M:%S.%N")-strptime(datefield1,"%Y-%m-%d %H:%M:%S.%N")
| eval duration_str=tostring(duration,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Aug 2018 18:04:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/how-to-subtract-two-date-and-time/m-p/384480#M69136</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-08-03T18:04:47Z</dc:date>
    </item>
  </channel>
</rss>

