<?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 calculate the number of days between two dates? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-number-of-days-between-two-dates/m-p/445504#M126378</link>
    <description>&lt;P&gt;Hi @kmaron above answer help me getting the days difference. Could you help me to count hour difference if daysdiff is less than 1.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Sep 2018 08:34:21 GMT</pubDate>
    <dc:creator>twh1</dc:creator>
    <dc:date>2018-09-07T08:34:21Z</dc:date>
    <item>
      <title>How to calculate the number of days between two dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-number-of-days-between-two-dates/m-p/445501#M126375</link>
      <description>&lt;P&gt;I have two dates as part of a string. I have to get these dates in separate fields by using the substr function. Now, I want to calculate the number of days difference between those two dates.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| base search
| eval date1=substr(HIGH_VALUE, 10, 19) 
| eval date2=substr(PREV_HIGH_VALUE, 10, 19) 
| eval it = strptime(date1, "%Y-%m-%d %H:%M:%S") 
| eval ot = strptime(date2, "%Y-%m-%d %H:%M:%S") 
| eval diff = (it - ot) | eval date_diff=strftime(diff,"%Y-%m-%d %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am unable to get the desired result by the above query. &lt;/P&gt;

&lt;P&gt;I have to calculate a new field data based on number of difference between two dates.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 17:27:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-number-of-days-between-two-dates/m-p/445501#M126375</guid>
      <dc:creator>twh1</dc:creator>
      <dc:date>2018-09-06T17:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the number of days between two dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-number-of-days-between-two-dates/m-p/445502#M126376</link>
      <description>&lt;P&gt;Hi @twh1,&lt;/P&gt;

&lt;P&gt;Try below query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| base search
| eval date1=substr(HIGH_VALUE, 10, 19) 
| eval date2=substr(PREV_HIGH_VALUE, 10, 19) 
| eval it = strptime(date1, "%Y-%m-%d %H:%M:%S") 
| eval ot = strptime(date2, "%Y-%m-%d %H:%M:%S") 
| eval diff = (it - ot)
| eval daysBetween=round(diff/86400,2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Sep 2018 17:45:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-number-of-days-between-two-dates/m-p/445502#M126376</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2018-09-06T17:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the number of days between two dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-number-of-days-between-two-dates/m-p/445503#M126377</link>
      <description>&lt;P&gt;try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| base search
| eval date1=substr(HIGH_VALUE, 10, 19) 
| eval date2=substr(PREV_HIGH_VALUE, 10, 19) 
| eval it = strptime(date1, "%Y-%m-%d %H:%M:%S") 
| eval ot = strptime(date2, "%Y-%m-%d %H:%M:%S") 
| eval daysdiff=round((ot-it)/86400,0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Sep 2018 17:53:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-number-of-days-between-two-dates/m-p/445503#M126377</guid>
      <dc:creator>kmaron</dc:creator>
      <dc:date>2018-09-06T17:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the number of days between two dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-number-of-days-between-two-dates/m-p/445504#M126378</link>
      <description>&lt;P&gt;Hi @kmaron above answer help me getting the days difference. Could you help me to count hour difference if daysdiff is less than 1.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 08:34:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-number-of-days-between-two-dates/m-p/445504#M126378</guid>
      <dc:creator>twh1</dc:creator>
      <dc:date>2018-09-07T08:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the number of days between two dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-number-of-days-between-two-dates/m-p/445505#M126379</link>
      <description>&lt;P&gt;The 86400 is the number of seconds in a day. So if you want hours instead just use 3600 instead. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval hoursdiff=round((ot-it)/3600,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;you could do some math in order to get days and hours so you always have both. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval daysdiff=round((ot-it)/86400,0)
 | eval hoursleft=(round((ot-it)/3600,0)-(daysdiff*24))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Sep 2018 12:04:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-number-of-days-between-two-dates/m-p/445505#M126379</guid>
      <dc:creator>kmaron</dc:creator>
      <dc:date>2018-09-07T12:04:06Z</dc:date>
    </item>
  </channel>
</rss>

