<?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: Comparison of two date fields gives bad result in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357158#M105653</link>
    <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;You can use &lt;CODE&gt;tonumber&lt;/CODE&gt; on both of your field to be sure they are Integer : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval myInt = tonumber(your_field)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;3no.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Jun 2017 12:35:28 GMT</pubDate>
    <dc:creator>3no</dc:creator>
    <dc:date>2017-06-19T12:35:28Z</dc:date>
    <item>
      <title>Comparison of two date fields gives bad result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357157#M105652</link>
      <description>&lt;P&gt;I use the following query in an  attempt to view a subset of the file test10UniqueActiveUsers.csv&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|inputlookup test10UniqueActiveUsers.csv | eval t=relative_time(now(), "-200d@d") | eval fa=strptime(firstactivity, "%s") | search "fa"&amp;lt;="t" |table fa, t, firstactivity
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However the clause "fa"&amp;lt;="t" is always true and it returns the whole table.&lt;BR /&gt;
If I do not use the generated ield t and instead put in the exact numeric value the it works fine. So &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|inputlookup test10UniqueActiveUsers.csv | eval t=relative_time(now(), "-200d@d") | eval fa=strptime(firstactivity, "%s") | search "fa"&amp;lt;=1480550400.0 |table fa, t, firstactivity
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;works perfectly for &amp;gt;= or &amp;lt;=.&lt;BR /&gt;
In the output table I can see that t is in fact equal to 1480550400.0, so the two queries above should be exactly equivalent. &lt;/P&gt;

&lt;P&gt;The only thing I can think of is that one of the fields might have an odd type like a string, and a number string comparison is happening, but I do not know how to confirm or fix that.&lt;/P&gt;

&lt;P&gt;For the first query where the comparison is always true the output is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fa                            t      firstactivity  
1484407682.000000   1480550400.000000   1484407682
1479115786.000000   1480550400.000000   1479115786
1484531129.000000   1480550400.000000   1484531129
1481212575.000000   1480550400.000000   1481212575
1490712727.000000   1480550400.000000   1490712727
1482140767.000000   1480550400.000000   1482140767
1476115342.000000   1480550400.000000   1476115342
1484696713.000000   1480550400.000000   1484696713
1489640643.000000   1480550400.000000   1489640643 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Jun 2017 07:40:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357157#M105652</guid>
      <dc:creator>niamurph</dc:creator>
      <dc:date>2017-06-19T07:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of two date fields gives bad result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357158#M105653</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;You can use &lt;CODE&gt;tonumber&lt;/CODE&gt; on both of your field to be sure they are Integer : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval myInt = tonumber(your_field)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;3no.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 12:35:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357158#M105653</guid>
      <dc:creator>3no</dc:creator>
      <dc:date>2017-06-19T12:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of two date fields gives bad result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357159#M105654</link>
      <description>&lt;P&gt;I tried that and nothing changed - maybe my theory about the field type is wrong and the cause is something else. I am baffled !&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 13:30:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357159#M105654</guid>
      <dc:creator>niamurph</dc:creator>
      <dc:date>2017-06-19T13:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of two date fields gives bad result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357160#M105655</link>
      <description>&lt;P&gt;Try with  : &lt;BR /&gt;
    | search fa&amp;lt;=t  (without the "")&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 13:54:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357160#M105655</guid>
      <dc:creator>3no</dc:creator>
      <dc:date>2017-06-19T13:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of two date fields gives bad result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357161#M105656</link>
      <description>&lt;P&gt;Sorry - I tried that as well. No success. I only added the " s when the version without failed !!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 14:46:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357161#M105656</guid>
      <dc:creator>niamurph</dc:creator>
      <dc:date>2017-06-19T14:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of two date fields gives bad result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357162#M105657</link>
      <description>&lt;P&gt;When comparing the values of two fields, do not use &lt;CODE&gt;search&lt;/CODE&gt;, use &lt;CODE&gt;where&lt;/CODE&gt;.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | where fa&amp;lt;=t
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;search&lt;/CODE&gt; keyword assumes the item on the left is a field name and the item on the right is a value.  The &lt;CODE&gt;where&lt;/CODE&gt; keyword allows both sides to be evaluated.&lt;/P&gt;

&lt;P&gt;See the section on comparing two fields, midway down this page...&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/6.6.0/SearchReference/Search"&gt;http://docs.splunk.com/Documentation/SplunkCloud/6.6.0/SearchReference/Search&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 15:06:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357162#M105657</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-06-19T15:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of two date fields gives bad result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357163#M105658</link>
      <description>&lt;P&gt;Thanks  - that fixed it.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 15:11:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357163#M105658</guid>
      <dc:creator>niamurph</dc:creator>
      <dc:date>2017-06-19T15:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of two date fields gives bad result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357164#M105659</link>
      <description>&lt;P&gt;Oh actually I have it working onw, and it needs the " removed alright - but the original cause was the fact that I used 'search' instead of 'where'&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 15:12:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparison-of-two-date-fields-gives-bad-result/m-p/357164#M105659</guid>
      <dc:creator>niamurph</dc:creator>
      <dc:date>2017-06-19T15:12:51Z</dc:date>
    </item>
  </channel>
</rss>

