<?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 Compare dates in splunk in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Compare-dates-in-splunk/m-p/177799#M186763</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have the below query to compare the date I am extracting from logs with the current date:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(sourcetype="XYZ") OR (sourcetype="ABC") 
| rex "\|Some String\|\w+\|(?&amp;lt;Field1&amp;gt;[AEU]\d{9})\|" 
| rex "(?P&amp;lt;Date&amp;gt;\d+\/\d+\/\d+\|\d+:\d+:\d+.\d+[^\|]+)"  
| eval DatetimeEpoch=strptime(Date,"%Y/%m/%d %H:%M:%S") 
| eval epoch30minsago=relative_time(now(), "-30m@m" )  
| stats first(sourcetype) as last_sourcetype first(Date) by Field1 
| search last_sourcetype="XYZ" 
| where DatetimeEpoch&amp;gt;=epoch30minsago
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to print out the values of Field1 if the field "Date" is 30 mins behind the current time.&lt;/P&gt;

&lt;P&gt;The format of the filed "Date" is below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2013/12/12|07:01:01.311
2013/12/12|07:20:17.464
2013/12/12|07:23:52.217
2013/12/12|07:24:52.480
2013/12/12|07:25:42.285
2013/12/12|07:25:49.494
2013/12/12|07:26:24.669
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please let me know how can I compare this with the current time/date. My query above is not working probably because the field "Date" is in string format and splunk is not able to convert it to epoch?&lt;/P&gt;</description>
    <pubDate>Fri, 13 Dec 2013 09:38:19 GMT</pubDate>
    <dc:creator>sriva6</dc:creator>
    <dc:date>2013-12-13T09:38:19Z</dc:date>
    <item>
      <title>Compare dates in splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-dates-in-splunk/m-p/177799#M186763</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have the below query to compare the date I am extracting from logs with the current date:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(sourcetype="XYZ") OR (sourcetype="ABC") 
| rex "\|Some String\|\w+\|(?&amp;lt;Field1&amp;gt;[AEU]\d{9})\|" 
| rex "(?P&amp;lt;Date&amp;gt;\d+\/\d+\/\d+\|\d+:\d+:\d+.\d+[^\|]+)"  
| eval DatetimeEpoch=strptime(Date,"%Y/%m/%d %H:%M:%S") 
| eval epoch30minsago=relative_time(now(), "-30m@m" )  
| stats first(sourcetype) as last_sourcetype first(Date) by Field1 
| search last_sourcetype="XYZ" 
| where DatetimeEpoch&amp;gt;=epoch30minsago
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to print out the values of Field1 if the field "Date" is 30 mins behind the current time.&lt;/P&gt;

&lt;P&gt;The format of the filed "Date" is below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2013/12/12|07:01:01.311
2013/12/12|07:20:17.464
2013/12/12|07:23:52.217
2013/12/12|07:24:52.480
2013/12/12|07:25:42.285
2013/12/12|07:25:49.494
2013/12/12|07:26:24.669
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please let me know how can I compare this with the current time/date. My query above is not working probably because the field "Date" is in string format and splunk is not able to convert it to epoch?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2013 09:38:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-dates-in-splunk/m-p/177799#M186763</guid>
      <dc:creator>sriva6</dc:creator>
      <dc:date>2013-12-13T09:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Compare dates in splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-dates-in-splunk/m-p/177800#M186764</link>
      <description>&lt;P&gt;Look, is this "Date" field in your events the same timestamp information that Splunk uses for indexing purposes? If so, then that information is already available in the &lt;CODE&gt;_time&lt;/CODE&gt; field, so you don't have to extract it again with &lt;CODE&gt;rex&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Check it with;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search for events | head 3 | table _time, Date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Do the timestamps match?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2013 12:19:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-dates-in-splunk/m-p/177800#M186764</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-12-13T12:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Compare dates in splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-dates-in-splunk/m-p/177801#M186765</link>
      <description>&lt;P&gt;Also: have you seen &lt;A href="http://apps.splunk.com/app/1645/"&gt;the Timewrap app&lt;/A&gt;?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2013 18:30:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-dates-in-splunk/m-p/177801#M186765</guid>
      <dc:creator>ChrisG</dc:creator>
      <dc:date>2013-12-13T18:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Compare dates in splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-dates-in-splunk/m-p/177802#M186766</link>
      <description>&lt;P&gt;Your &lt;CODE&gt;strptime()&lt;/CODE&gt; format doesn't match the Date field.  Try &lt;CODE&gt;"%Y/%m/%d %H:%M:%S.%3Q"&lt;/CODE&gt;.  Also the where clause should read &lt;CODE&gt;'where DatetimeEpoch &amp;lt;= epoch30minsago'&lt;/CODE&gt; to select events at least 30 minutes behind the current time.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2013 18:33:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-dates-in-splunk/m-p/177802#M186766</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2013-12-13T18:33:25Z</dc:date>
    </item>
  </channel>
</rss>

