<?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 Date comparison in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Date-comparison/m-p/154286#M43395</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I would like to compare two dates:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;log_time&lt;/STRONG&gt; 08/Dec/2014:15:36:34 +1100&lt;BR /&gt;
&lt;STRONG&gt;_time&lt;/STRONG&gt; 2014-12-08 15:36:34&lt;/P&gt;

&lt;P&gt;It is my expectation that I can use the below query to compare these dates and identify any log entries where they do not match. This is part of my QA process over indexed log data. &lt;/P&gt;

&lt;P&gt;I have been trying the following query but get no results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="sec_ldap" | eval compare=strftime(log_time,"%Y-%m-%d %H:%M:%S") | where compare!=strftime(_time,"%Y-%m-%d %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have followed this up by changing the Boolean operator from "!=" to "&amp;gt;" to "&amp;lt;" and to "=" just to confirm it's not the Boolean operater that's yielding unexpected results.  I still get no results.&lt;/P&gt;

&lt;P&gt;I then ran the following query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="sec_ldap" | eval compare1=strftime(log_time,"%Y-%m-%d %H:%M:%S") | eval compare2=strftime(_time,"%Y-%m-%d %H:%M:%S") |table compare1 compare2 _raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is how I realised the formats, even after running the strftime() function, don't match (see above).&lt;/P&gt;

&lt;P&gt;Any pointers? I'm wondering if it's a matter of the "log_time" value being considered a "String" whereas _time is considered a "Date" or "Time" data type?&lt;/P&gt;

&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
P&lt;/P&gt;</description>
    <pubDate>Mon, 08 Dec 2014 05:38:44 GMT</pubDate>
    <dc:creator>pjb2160</dc:creator>
    <dc:date>2014-12-08T05:38:44Z</dc:date>
    <item>
      <title>Date comparison</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-comparison/m-p/154286#M43395</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I would like to compare two dates:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;log_time&lt;/STRONG&gt; 08/Dec/2014:15:36:34 +1100&lt;BR /&gt;
&lt;STRONG&gt;_time&lt;/STRONG&gt; 2014-12-08 15:36:34&lt;/P&gt;

&lt;P&gt;It is my expectation that I can use the below query to compare these dates and identify any log entries where they do not match. This is part of my QA process over indexed log data. &lt;/P&gt;

&lt;P&gt;I have been trying the following query but get no results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="sec_ldap" | eval compare=strftime(log_time,"%Y-%m-%d %H:%M:%S") | where compare!=strftime(_time,"%Y-%m-%d %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have followed this up by changing the Boolean operator from "!=" to "&amp;gt;" to "&amp;lt;" and to "=" just to confirm it's not the Boolean operater that's yielding unexpected results.  I still get no results.&lt;/P&gt;

&lt;P&gt;I then ran the following query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="sec_ldap" | eval compare1=strftime(log_time,"%Y-%m-%d %H:%M:%S") | eval compare2=strftime(_time,"%Y-%m-%d %H:%M:%S") |table compare1 compare2 _raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is how I realised the formats, even after running the strftime() function, don't match (see above).&lt;/P&gt;

&lt;P&gt;Any pointers? I'm wondering if it's a matter of the "log_time" value being considered a "String" whereas _time is considered a "Date" or "Time" data type?&lt;/P&gt;

&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
P&lt;/P&gt;</description>
      <pubDate>Mon, 08 Dec 2014 05:38:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-comparison/m-p/154286#M43395</guid>
      <dc:creator>pjb2160</dc:creator>
      <dc:date>2014-12-08T05:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Date comparison</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-comparison/m-p/154287#M43396</link>
      <description>&lt;P&gt;Yes, it is because log_time is a string. Try it this way&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="sec_ldap" 
| eval compare1=strptime(log_time,"%m/%d/%Y:%H:%M:%S") 
| where compare1!=_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This compares both variables in time format.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Dec 2014 07:50:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-comparison/m-p/154287#M43396</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2014-12-08T07:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: Date comparison</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-comparison/m-p/154288#M43397</link>
      <description>&lt;P&gt;Thanks very much for your response, I tried your suggestion but you used a %d instead of a %b for the format (no problem though easily resolved!!)&lt;/P&gt;

&lt;P&gt;I also revised the query to compare a sub-string removing the "+1100" from log_time:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="sec_ldap"
 | eval log_time_sub=substr(log_time,1,20)
 | eval compare1=strptime(log_time_sub,"%d/%b/%Y:%H:%M:%S")
 | where compare1!=_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks again, much appreciated!&lt;BR /&gt;
P&lt;/P&gt;</description>
      <pubDate>Mon, 08 Dec 2014 23:15:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-comparison/m-p/154288#M43397</guid>
      <dc:creator>pjb2160</dc:creator>
      <dc:date>2014-12-08T23:15:06Z</dc:date>
    </item>
  </channel>
</rss>

