<?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 find the difference between two timestamp string fields in two different indexes? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179617#M51715</link>
    <description>&lt;P&gt;Yes, @ppablo_splunk, you are right. I have corrected the format. Now it is working( for same indexes), but I want to compare for two different indexes using "EmpID" which is present on both index logs.&lt;/P&gt;

&lt;P&gt;Please suggest.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 19 Mar 2015 08:07:54 GMT</pubDate>
    <dc:creator>varunnair26</dc:creator>
    <dc:date>2015-03-19T08:07:54Z</dc:date>
    <item>
      <title>How to find the difference between two timestamp string fields in two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179608#M51706</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;In my Splunk instance there are two indexes which I need to use for arithmetic operations on the timestamp fields of the logs. For example, first index contains logs set with timestamp field "&lt;STRONG&gt;In Swipe&lt;/STRONG&gt;" in format "&lt;STRONG&gt;dd/mm/yy hh:mm:ss&lt;/STRONG&gt;", and the other index logs set have timestamp field "&lt;STRONG&gt;Login Time&lt;/STRONG&gt;" in same format "&lt;STRONG&gt;dd/mm/yy hh:mm:ss&lt;/STRONG&gt;". I need to take the difference between these two fields and check whether it is a negative or a positive value (below mentioned operation).&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Login Time - In Swipe &amp;gt; 0&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I was trying with &lt;STRONG&gt;WHERE&lt;/STRONG&gt; and &lt;STRONG&gt;EVAL&lt;/STRONG&gt; command, but both of them take only numbers for any arithmetic operation.&lt;/P&gt;

&lt;P&gt;Please suggest.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2015 08:50:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179608#M51706</guid>
      <dc:creator>varunnair26</dc:creator>
      <dc:date>2015-03-18T08:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference between two timestamp string fields in two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179609#M51707</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;

&lt;P&gt;You need to transform those timestamps to epoch and then do the operations. Like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... yourbase search | eval swipe=strptime(swipe_time,"%d/%m/%y %H:%M:%S) | eval login=strptime(login_time,"%d/%m/%y %H:%M:%S) | eval diff= swipe_time - login_time | where diff &amp;gt;0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2015 08:55:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179609#M51707</guid>
      <dc:creator>gfuente</dc:creator>
      <dc:date>2015-03-18T08:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference between two timestamp string fields in two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179610#M51708</link>
      <description>&lt;P&gt;@gfuente: Thanks for the reply. Below is the exact search which I am trying:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;|eval swipe=strptime("In Swipe",'%d/%m/%y %H:%M:%S') | eval login=strptime(LoginTime,'%d/%m/%y %H:%M:%S') | eval diff = swipe-login | where diff &amp;gt; 0&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;But it says, "no result". I have tried reverted where condition (&lt;STRONG&gt;where diff &amp;lt; 0&lt;/STRONG&gt;) also, still it says "no result". It should populate result in either ways.&lt;/P&gt;

&lt;P&gt;Please suggest what I am doing wrong here.&lt;/P&gt;

&lt;P&gt;Thanks. &lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2015 10:02:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179610#M51708</guid>
      <dc:creator>varunnair26</dc:creator>
      <dc:date>2015-03-18T10:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference between two timestamp string fields in two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179611#M51709</link>
      <description>&lt;P&gt;Can you post some sample events? or at least the contents of those fields&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2015 10:41:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179611#M51709</guid>
      <dc:creator>gfuente</dc:creator>
      <dc:date>2015-03-18T10:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference between two timestamp string fields in two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179612#M51710</link>
      <description>&lt;P&gt;By the way there is an error on the first eval:&lt;/P&gt;

&lt;P&gt;("In Swipe"&lt;/P&gt;

&lt;P&gt;You can't use " as splunk thinks is a string. If your field has spaces, use $ to surround it, like: $In Swipe$&lt;/P&gt;

&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2015 10:43:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179612#M51710</guid>
      <dc:creator>gfuente</dc:creator>
      <dc:date>2015-03-18T10:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference between two timestamp string fields in two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179613#M51711</link>
      <description>&lt;P&gt;@gfuente: I tried this also.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;|eval swipe=strptime($In Swipe$,'%d/%m/%y %H:%M:%S') | eval login=strptime(LoginTime,'%d/%m/%y %H:%M:%S') | eval diff = swipe-login | where diff &amp;gt; 0&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Still it says, " no result"&lt;/P&gt;

&lt;P&gt;Below are the sample of logs:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Index 1&lt;/STRONG&gt;(TimeStamp field=&lt;STRONG&gt;In Swipe&lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;EmpID,Asset,EmpName,3/11/2015 23:55&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Index 2&lt;/STRONG&gt;(TimeStamp field=&lt;STRONG&gt;LoginTime&lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;EmpID,CardNumber,EmpName,3/11/2015 22:18&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;In these logs, I need difference of the timestamp fields, so that I can check the sequence of logs for the same &lt;STRONG&gt;EmpID&lt;/STRONG&gt;, whether &lt;STRONG&gt;LoginTime&lt;/STRONG&gt; is prior to &lt;STRONG&gt;In Swipe&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;Thanks &lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2015 11:09:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179613#M51711</guid>
      <dc:creator>varunnair26</dc:creator>
      <dc:date>2015-03-18T11:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference between two timestamp string fields in two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179614#M51712</link>
      <description>&lt;P&gt;Hi @varunnair26&lt;/P&gt;

&lt;P&gt;Are you sure the format of your timestamps is actually "&lt;STRONG&gt;dd/mm/yy hh:mm:ss&lt;/STRONG&gt;"? I'm guessing these logs are not from November 3, 2015, but are actually March 11, 2015 if you are using real dates in the sample logs you provided. If yes, I bet that's the problem because you're attempting to transform a future timestamp with &lt;STRONG&gt;%d/%m&lt;/STRONG&gt; when really it should be &lt;STRONG&gt;%m/%d&lt;/STRONG&gt;. Can you try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...your base search... | eval swipe=strptime($In Swipe$,'%m/%d/%y %H:%M:%S') | eval login=strptime(LoginTime,'%m/%d/%y %H:%M:%S') | eval diff = swipe-login | where diff &amp;gt; 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also, are there seconds in any of the timestamps? If not then you should use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...your base search... | eval swipe=strptime($In Swipe$,'%m/%d/%y %H:%M') | eval login=strptime(LoginTime,'%m/%d/%y %H:%M') | eval diff = swipe-login | where diff &amp;gt; 0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Mar 2015 18:01:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179614#M51712</guid>
      <dc:creator>ppablo</dc:creator>
      <dc:date>2015-03-18T18:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference between two timestamp string fields in two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179615#M51713</link>
      <description>&lt;P&gt;Queries:&lt;BR /&gt;
1)  Do the field "In Swipe" and "Login Time" available on same event OR they come from different event?  [Any eval operation is done per event/row so if both fields are not available in same row, you'll not get the desired result.]&lt;BR /&gt;
2) Format of datetime fields is expected to be"%d/%m/%y %H:%M:%S" (based on your search). But based on your sample data in one of comments, the data is in "%d/%m/%y %H:%M" (no seconds). The strptime function need the format to match exactly.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2015 18:24:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179615#M51713</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-03-18T18:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference between two timestamp string fields in two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179616#M51714</link>
      <description>&lt;P&gt;1) Both events are from different indexes. &lt;BR /&gt;
2) I have corrected the format. (It is working when I tried for same index comparison) &lt;/P&gt;

&lt;P&gt;But I am trying to compare two events from different indexes, using the "EmpID" as a reference which is present in both the index logs. &lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2015 07:32:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179616#M51714</guid>
      <dc:creator>varunnair26</dc:creator>
      <dc:date>2015-03-19T07:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference between two timestamp string fields in two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179617#M51715</link>
      <description>&lt;P&gt;Yes, @ppablo_splunk, you are right. I have corrected the format. Now it is working( for same indexes), but I want to compare for two different indexes using "EmpID" which is present on both index logs.&lt;/P&gt;

&lt;P&gt;Please suggest.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2015 08:07:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179617#M51715</guid>
      <dc:creator>varunnair26</dc:creator>
      <dc:date>2015-03-19T08:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference between two timestamp string fields in two different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179618#M51716</link>
      <description>&lt;P&gt;This issue is resolved. i have used transaction to group the indexes then compared their timestamps.&lt;/P&gt;

&lt;P&gt;Thank you @gfuente, @ppablo_splunk for your help regarding the timestamp format.&lt;/P&gt;

&lt;P&gt;rgds&lt;BR /&gt;
Varun&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2015 06:23:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-between-two-timestamp-string-fields/m-p/179618#M51716</guid>
      <dc:creator>varunnair26</dc:creator>
      <dc:date>2015-03-25T06:23:10Z</dc:date>
    </item>
  </channel>
</rss>

