<?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 convert date differences to seconds in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494895#M137946</link>
    <description>&lt;P&gt;hello.&lt;/P&gt;

&lt;P&gt;|eval temp=strptime(start_time, "%Y-%m-%d %H:%M:%S.%Q")&lt;BR /&gt;
|eval temp1=temp+duration&lt;BR /&gt;
|eval end_time=strftime(temp1,"%Y-%m-%d %H:%M:%S.%Q")&lt;/P&gt;

&lt;P&gt;|table start_time end_time duration&lt;BR /&gt;
|stats avg(duration) as qwe&lt;/P&gt;

&lt;P&gt;|eval HH=floor(qwe/3600)&lt;BR /&gt;
|eval MM=floor((qwe-(HH*3600))/60)&lt;BR /&gt;
|eval SS=round(qwe-(HH*3600)-(MM*60),0)&lt;/P&gt;

&lt;P&gt;|eval avg_duration=(HH + ":" + MM + ":" +SS)&lt;BR /&gt;
|fields avg_duration&lt;/P&gt;

&lt;P&gt;I expressed the hour and minute by the following command. It is possible by subtracting the minute from the average time and subtracting the minute from this part.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 04:33:42 GMT</pubDate>
    <dc:creator>jinseong</dc:creator>
    <dc:date>2020-09-30T04:33:42Z</dc:date>
    <item>
      <title>How to convert date differences to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494886#M137937</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I have a lookup like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    caseid date
    a          19-01-01 15:54:43.934000000
    b          19-01-01 16:54:43.934000000
    c          19-01-01 17:54:43.934000000
    d          19-01-01 18:54:43.934000000
    e
    f
    g
    .
    .
    .
    .
    .
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I did this command&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup test1
    | eval date=strptime(date,"%y-%m-%d %H:%M:%S.%9N") 
    | stats min(date) as starttime max(date) as endtime by caseid
    | eval diff =endtime-starttime 
    | stats avg(diff) as average
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;my result is like this.(this is dummy)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;average
999999.9999999
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to get results like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;average
3600
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(this is 1 hour)&lt;BR /&gt;
I understand I have to convert, but I don't know how to convert date differences to seconds.&lt;BR /&gt;
Could you help me?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 04:31:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494886#M137937</guid>
      <dc:creator>pipipipi</dc:creator>
      <dc:date>2020-03-12T04:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date differences to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494887#M137938</link>
      <description>&lt;P&gt;As such:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw = "caseid,date
 a, 19-01-01 15:54:43.934000000
 b, 19-01-01 16:54:43.934000000
 c, 19-01-01 17:54:43.934000000
 d, 19-01-01 18:54:43.934000000" 
| multikv forceheader=1 
| eval date_new=strptime(date,"%y-%m-%d %H:%M:%S.%9N") 
| eventstats min(date_new) as starttime max(date_new) as endtime count as totalevents 
| eval avg = round((endtime-starttime) / totalevents, 1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Mar 2020 04:52:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494887#M137938</guid>
      <dc:creator>anmolpatel</dc:creator>
      <dc:date>2020-03-12T04:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date differences to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494888#M137939</link>
      <description>&lt;P&gt;@pipipipi &lt;/P&gt;

&lt;P&gt;Do you want to round?&lt;BR /&gt;
Like by adding this in below search?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval average=round(average,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried your search with different data it is working.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw=" caseid date
 a          19-01-01 15:54:43.934000000
 b          19-01-01 16:54:43.934000000
 c          19-01-01 17:54:43.934000000
 d          19-01-01 18:54:43.934000000
 a          19-01-01 18:54:43.934000000
 b          19-01-01 19:54:43.934000000
 c          19-01-01 20:54:43.934000000
 d          19-01-01 21:54:43.934000000" 
| multikv forceheader=1 
| eval date=strptime(date,"%y-%m-%d %H:%M:%S.%9N") 
| stats min(date) as starttime max(date) as endtime by caseid 
| eval diff =endtime-starttime 
| stats avg(diff) as average | eval average=round(average,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please let us know if you have different expectations.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 04:56:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494888#M137939</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2020-03-12T04:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date differences to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494889#M137940</link>
      <description>&lt;P&gt;Thank you for helping me. &lt;BR /&gt;
Sorry, my English is bad.&lt;/P&gt;

&lt;P&gt;I want to convert 99999.9999(this is example value) to 3600.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval diff =endtime-starttime 
| stats avg(diff) as average
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;is date difference, I want to express the date difference in seconds&lt;/P&gt;

&lt;P&gt;Thank you for helping&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 05:04:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494889#M137940</guid>
      <dc:creator>pipipipi</dc:creator>
      <dc:date>2020-03-12T05:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date differences to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494890#M137941</link>
      <description>&lt;P&gt;Thank you for helping me.&lt;BR /&gt;
I have about 15000 column, so, &lt;BR /&gt;
|eval _raw........ is difficult for me.&lt;/P&gt;

&lt;P&gt;Thank you so much.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 05:08:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494890#M137941</guid>
      <dc:creator>pipipipi</dc:creator>
      <dc:date>2020-03-12T05:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date differences to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494891#M137942</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/194061"&gt;@pipipipi&lt;/a&gt; the _raw line is to demonstrate the example.&lt;/P&gt;

&lt;P&gt;In your case, you will have the following:&lt;BR /&gt;
    | inputlookup test1&lt;BR /&gt;
    | eval date_new=strptime(date,"%y-%m-%d %H:%M:%S.%9N") &lt;BR /&gt;
    | eventstats min(date_new) as starttime max(date_new) as endtime count as totalevents &lt;BR /&gt;
    | eval avg = round((endtime-starttime) / totalevents,1)&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:33:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494891#M137942</guid>
      <dc:creator>anmolpatel</dc:creator>
      <dc:date>2020-09-30T04:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date differences to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494892#M137943</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup test1
| eval date=strptime(date,"%y-%m-%d %H:%M:%S.%9N") 
| stats range(date) AS diff BY caseid
| stats avg(diff) AS average
| fieldformat average = tostring(average, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Mar 2020 06:23:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494892#M137943</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-12T06:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date differences to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494893#M137944</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;999999.9999999 *+-/ ? = 3600
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;what's your formula?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 09:48:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494893#M137944</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-03-12T09:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date differences to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494894#M137945</link>
      <description>&lt;P&gt;Thank you for helping me.&lt;BR /&gt;
When I using tostring, What is the unit of time? I think seconds, is it right?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 00:38:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494894#M137945</guid>
      <dc:creator>pipipipi</dc:creator>
      <dc:date>2020-03-13T00:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date differences to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494895#M137946</link>
      <description>&lt;P&gt;hello.&lt;/P&gt;

&lt;P&gt;|eval temp=strptime(start_time, "%Y-%m-%d %H:%M:%S.%Q")&lt;BR /&gt;
|eval temp1=temp+duration&lt;BR /&gt;
|eval end_time=strftime(temp1,"%Y-%m-%d %H:%M:%S.%Q")&lt;/P&gt;

&lt;P&gt;|table start_time end_time duration&lt;BR /&gt;
|stats avg(duration) as qwe&lt;/P&gt;

&lt;P&gt;|eval HH=floor(qwe/3600)&lt;BR /&gt;
|eval MM=floor((qwe-(HH*3600))/60)&lt;BR /&gt;
|eval SS=round(qwe-(HH*3600)-(MM*60),0)&lt;/P&gt;

&lt;P&gt;|eval avg_duration=(HH + ":" + MM + ":" +SS)&lt;BR /&gt;
|fields avg_duration&lt;/P&gt;

&lt;P&gt;I expressed the hour and minute by the following command. It is possible by subtracting the minute from the average time and subtracting the minute from this part.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:33:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494895#M137946</guid>
      <dc:creator>jinseong</dc:creator>
      <dc:date>2020-09-30T04:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date differences to seconds</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494896#M137947</link>
      <description>&lt;P&gt;It auto-ranges the output but keeps the actual value as &lt;CODE&gt;seconds&lt;/CODE&gt; stored as a number (unitless).&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 11:02:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-differences-to-seconds/m-p/494896#M137947</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-16T11:02:26Z</dc:date>
    </item>
  </channel>
</rss>

