<?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 difference between 2 dates and times with strftime in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/calculate-difference-between-2-dates-and-times-with-strftime/m-p/467790#M131676</link>
    <description>&lt;P&gt;I have the below search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=cd  source=jenkins pr_number=*
| stats count as Total , earliest(_time) as start, latest(_time) as stop by pr_number name stage.steps{}.stage
| eval start=strftime(start, "%d/%m/%y - %I:%M:%S:%p") 
| eval stop=strftime(stop, "%d/%m/%y - %I:%M:%S:%p")
| eval diffTime=stop - start
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the evals for start and stop are working fine but the eval for difftime is not working. As I'm using strftime how can i calculate the duration between the 2 dates and times? &lt;/P&gt;</description>
    <pubDate>Tue, 07 Apr 2020 12:06:28 GMT</pubDate>
    <dc:creator>Sfry1981</dc:creator>
    <dc:date>2020-04-07T12:06:28Z</dc:date>
    <item>
      <title>calculate difference between 2 dates and times with strftime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-difference-between-2-dates-and-times-with-strftime/m-p/467790#M131676</link>
      <description>&lt;P&gt;I have the below search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=cd  source=jenkins pr_number=*
| stats count as Total , earliest(_time) as start, latest(_time) as stop by pr_number name stage.steps{}.stage
| eval start=strftime(start, "%d/%m/%y - %I:%M:%S:%p") 
| eval stop=strftime(stop, "%d/%m/%y - %I:%M:%S:%p")
| eval diffTime=stop - start
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the evals for start and stop are working fine but the eval for difftime is not working. As I'm using strftime how can i calculate the duration between the 2 dates and times? &lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 12:06:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-difference-between-2-dates-and-times-with-strftime/m-p/467790#M131676</guid>
      <dc:creator>Sfry1981</dc:creator>
      <dc:date>2020-04-07T12:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference between 2 dates and times with strftime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-difference-between-2-dates-and-times-with-strftime/m-p/467791#M131677</link>
      <description>&lt;P&gt;Splunk cannot do calculations on dates in string form.  They must be converted to epoch (integer) form using &lt;CODE&gt;strptime&lt;/CODE&gt; first.  Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=cd  source=jenkins pr_number=*
| stats count as Total , earliest(_time) as start, latest(_time) as stop by pr_number name stage.steps{}.stage
| eval diffTime=stop - start
| eval start=strftime(start, "%d/%m/%y - %I:%M:%S:%p") 
| eval stop=strftime(stop, "%d/%m/%y - %I:%M:%S:%p")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Apr 2020 12:29:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-difference-between-2-dates-and-times-with-strftime/m-p/467791#M131677</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-04-07T12:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference between 2 dates and times with strftime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-difference-between-2-dates-and-times-with-strftime/m-p/467792#M131678</link>
      <description>&lt;P&gt;You're modifying start and stop into patterns that don't work with the math you're trying to apply. Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=cd  source=jenkins pr_number=*
| stats count as Total , earliest(_time) as start, latest(_time) as stop by pr_number name stage.steps{}.stage
| eval newStart=strftime(start, "%d/%m/%y - %I:%M:%S:%p") 
| eval newStop=strftime(stop, "%d/%m/%y - %I:%M:%S:%p")
| eval diffTime=stop - start
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will give you diffTime in seconds, which you can do with what you want.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 12:30:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-difference-between-2-dates-and-times-with-strftime/m-p/467792#M131678</guid>
      <dc:creator>jpolvino</dc:creator>
      <dc:date>2020-04-07T12:30:37Z</dc:date>
    </item>
  </channel>
</rss>

