<?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: Search Query For Time Difference in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281459#M84920</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="wineventlog" source="wineventlog:security" EventCode="4624" (user=userID) 
| eval AD_Time=strftime(_time, "%Y/%m/%d %H:%M:%S")|eval Date1=_time|rename user AS Account
| join Account outer [search index=xyz sourcetype="xyz" act="Action" (duser=userID) 
| eval CA_Time=strftime(_time, "%Y/%m/%d %H:%M:%S")|eval Date2=_time| rename duser AS Account, act AS Action] 
| eval Timediff=Date1-Date2 | eval Timediff=strftime(Timediff,"%H:%M:%S") | table AD_Time Account CA_Time Action Timediff
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 16 Feb 2016 03:36:14 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2016-02-16T03:36:14Z</dc:date>
    <item>
      <title>Search Query For Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281458#M84919</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;My use case to find out 1st search user logon time in AD and same user logon time in 2nd search with his action, now need to find if user logon is complete but if he didn't do any action in 2nd search with duration not more than 30mins then I need to highlight that user with logon time,&lt;BR /&gt;
In the below query AD_Time showing correct, but CA_Time showing same date&amp;amp;time for all rows, not sure where am I missing and not getting what expected.&lt;/P&gt;

&lt;P&gt;index="wineventlog" source="wineventlog:security" EventCode="4624" (user=userID) |eval Date=strftime(_time, "%Y/%m/%d %H:%M:%S")|rename Date AS AD_Time, user AS Account| join outer [search index=xyz sourcetype="xyz" act="Action" (duser=userID) |eval Date=strftime(_time, "%Y/%m/%d %H:%M:%S")| rename Date AS CA_Time, duser AS Account, act AS Action] | eval Timediff=AD_Time-CA_Time | eval Timediff=strftime(_time,"%H:%M:%S") | table AD_Time Account CA_Time Action Timediff&lt;/P&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:45:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281458#M84919</guid>
      <dc:creator>kpavan</dc:creator>
      <dc:date>2020-09-29T08:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: Search Query For Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281459#M84920</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="wineventlog" source="wineventlog:security" EventCode="4624" (user=userID) 
| eval AD_Time=strftime(_time, "%Y/%m/%d %H:%M:%S")|eval Date1=_time|rename user AS Account
| join Account outer [search index=xyz sourcetype="xyz" act="Action" (duser=userID) 
| eval CA_Time=strftime(_time, "%Y/%m/%d %H:%M:%S")|eval Date2=_time| rename duser AS Account, act AS Action] 
| eval Timediff=Date1-Date2 | eval Timediff=strftime(Timediff,"%H:%M:%S") | table AD_Time Account CA_Time Action Timediff
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Feb 2016 03:36:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281459#M84920</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2016-02-16T03:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Search Query For Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281460#M84921</link>
      <description>&lt;P&gt;Hi Renjith,&lt;/P&gt;

&lt;P&gt;Thanks for your response,&lt;/P&gt;

&lt;P&gt;I tried the query, but Timediff showing wrong value, as showing below result the value of Timediff should be 04:14:22 but getting as 23:14:22 which is not correct. Could you please help on the same.&lt;/P&gt;

&lt;P&gt;AD_Time                        Account  CA_Time                          Action Timediff&lt;BR /&gt;
2016/02/05 08:28:44 userID 2016/02/05 04:14:22  Retrieve    23:14:22&lt;/P&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:45:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281460#M84921</guid>
      <dc:creator>kpavan</dc:creator>
      <dc:date>2020-09-29T08:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Search Query For Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281461#M84922</link>
      <description>&lt;P&gt;Sorry I didn't notice your conversion of &lt;EM&gt;difference&lt;/EM&gt; field. &lt;/P&gt;

&lt;P&gt;Try &lt;CODE&gt;eval Timediff=tostring(Timediff, "duration")&lt;/CODE&gt; instead of &lt;CODE&gt;eval Timediff=strftime(Timediff,"%H:%M:%S")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Final search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="wineventlog" source="wineventlog:security" EventCode="4624" (user=userID) 
 | eval AD_Time=strftime(_time, "%Y/%m/%d %H:%M:%S")|eval Date1=_time|rename user AS Account
 | join Account outer [search index=xyz sourcetype="xyz" act="Action" (duser=userID) 
 | eval CA_Time=strftime(_time, "%Y/%m/%d %H:%M:%S")|eval Date2=_time| rename duser AS Account, act AS Action] 
 | eval timediff=Date1-Date2 | eval Timediff=tostring(timediff, "duration") | table AD_Time Account CA_Time Action Timediff
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Feb 2016 09:23:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281461#M84922</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2016-02-16T09:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Search Query For Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281462#M84923</link>
      <description>&lt;P&gt;try like this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="wineventlog" source="wineventlog:security" EventCode="4624" (user=userID) |eval AD_Time=strftime(_time, "%Y/%m/%d %H:%M:%S")|rename  user AS Account| appendcols [search index=xyz sourcetype="xyz" act="Action" (duser=userID) |eval CA_Time=strftime(_time, "%Y/%m/%d %H:%M:%S")| rename  duser AS Account, act AS Action] | eval Timediff=AD_Time-CA_Time | eval Timediff=strftime(_time,"%H:%M:%S") | table AD_Time Account CA_Time Action Timediff
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Feb 2016 10:49:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281462#M84923</guid>
      <dc:creator>fdi01</dc:creator>
      <dc:date>2016-02-16T10:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: Search Query For Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281463#M84924</link>
      <description>&lt;P&gt;Hi Renjith,&lt;/P&gt;

&lt;P&gt;sorry to bother you again, tried your final query but Streamed search execute failed because: Invalid number and just edited little bit, now Timediff field not giving any value. something is missing.&lt;/P&gt;

&lt;P&gt;|eval timediff=strptime(Date1, "%Y/%m/%d %H:%M:%S") - strptime(Date2, "%Y/%m/%d %H:%M:%S") | eval Timediff=tostring(timediff, "duration")| table AD_Time Account CA_Time Action Timediff&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:45:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281463#M84924</guid>
      <dc:creator>kpavan</dc:creator>
      <dc:date>2020-09-29T08:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Search Query For Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281464#M84925</link>
      <description>&lt;P&gt;Try subtracting _time from bth search before formatting. Can you try this and share the output?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="wineventlog" source="wineventlog:security" EventCode="4624" (user=userID) 
  | eval AD_Time=strftime(_time, "%Y/%m/%d %H:%M:%S")|eval Date1=_time|rename user AS Account
  | join Account outer [search index=xyz sourcetype="xyz" act="Action" (duser=userID) 
  | eval CA_Time=strftime(_time, "%Y/%m/%d %H:%M:%S")|eval Date2=_time| rename duser AS Account, act AS Action] 
  | eval timediff=Date1-Date2|table AD_Time,CA_Time,Account,Action,Date1,Date2,timediff
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Feb 2016 13:23:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281464#M84925</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2016-02-16T13:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Search Query For Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281465#M84926</link>
      <description>&lt;P&gt;This is the output,&lt;BR /&gt;
AD_Time             CA_Time             Account Action      Date1       Date2       timediff&lt;BR /&gt;
2016/02/16 02:01:07 2016/02/07 22:58:44 userID1 Retrieve    1455606067  1454903924  702143&lt;BR /&gt;
2016/02/15 09:54:02 2016/02/10 01:16:18 userID2 Retrieve    1455548042  1455084978  463064&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:45:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281465#M84926</guid>
      <dc:creator>kpavan</dc:creator>
      <dc:date>2020-09-29T08:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Search Query For Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281466#M84927</link>
      <description>&lt;P&gt;This looks correct . Just add &lt;CODE&gt;|eval Timediff=tostring(timediff, "duration")&lt;/CODE&gt; to see the difference in hours,minutes and seconds.&lt;/P&gt;

&lt;P&gt;Result of my search gives difference as &lt;CODE&gt;8+03:02:23&lt;/CODE&gt; which is 8 days 3 hours,2 minutes,23 secs which is correct for my timezone&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 03:10:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281466#M84927</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2016-02-17T03:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Search Query For Time Difference</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281467#M84928</link>
      <description>&lt;P&gt;Hi Renjith,&lt;/P&gt;

&lt;P&gt;Actually tostring is giving me error as i said earlier like Invalid number, not sure why. So i have changed bit, i think got what expected.&lt;/P&gt;

&lt;P&gt;Thanks for your support!&lt;/P&gt;

&lt;P&gt;index="wineventlog" sourcetype="wineventlog:security" EventCode="4624" OR EventCode="4625"(user=userID)| eval AD_Time=strftime(_time, "%Y/%m/%d %H:%M:%S")|eval Date1=_time|search NOT Source_Network_Address="-" |rename user AS Account, Source_Network_Address AS SourceIP| join Account outer [search index=xyz sourcetype="xyz" act="Action" (duser=userID)| eval CA_Time=strftime(_time, "%Y/%m/%d %H:%M:%S")|eval Date2=_time| rename duser AS Account, act AS Action]| eval Timediff=round(('Date1'-'Date2')/3600) | dedup AD_Time | where Timediff &amp;gt; 1 |table AD_Time Account SourceIP Timediff&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:49:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-Query-For-Time-Difference/m-p/281467#M84928</guid>
      <dc:creator>kpavan</dc:creator>
      <dc:date>2020-09-29T08:49:29Z</dc:date>
    </item>
  </channel>
</rss>

