<?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: Compare a date field with current date in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65064#M16092</link>
    <description>&lt;P&gt;I have some thoughts, but this question deserves its own top-level question so that others can offer their own insight. Also, people looking for answers to questions like yours will find a more targeted answer. Don't be afraid to open a whole new question &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Sep 2018 13:20:21 GMT</pubDate>
    <dc:creator>reed_kelly</dc:creator>
    <dc:date>2018-09-26T13:20:21Z</dc:date>
    <item>
      <title>Compare a date field with current date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65056#M16084</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have some events into splunk which I would like to compare with today's date less than 30 days.&lt;BR /&gt;
I want to exctract all the events which are older than 30 days like this.&lt;/P&gt;

&lt;P&gt;The date field in the events has this form : Date="2012-09-24" which is %Y-%m-%d&lt;/P&gt;

&lt;P&gt;How could I get the current splunk date in my search and make a compare with the date field ?&lt;BR /&gt;
I suppose the use of epoch values ​​as proposed here could be a solution once the current date obtained.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://splunk-base.splunk.com/answers/37272/compare-two-date"&gt;http://splunk-base.splunk.com/answers/37272/compare-two-date&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2012 12:55:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65056#M16084</guid>
      <dc:creator>rbw78</dc:creator>
      <dc:date>2012-09-19T12:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a date field with current date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65057#M16085</link>
      <description>&lt;P&gt;Do you mean that the date field is different from the event's timestamp? So you want to compare the timestamp to some date in the event?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2012 13:45:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65057#M16085</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-09-19T13:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a date field with current date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65058#M16086</link>
      <description>&lt;P&gt;To get the current date, you can just add:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;|eval timenow=now()&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;This gets epoch time into the field timenow. If you want to format it, you can use strftime:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;|eval nowstring=strftime(now(), "%Y-%m-%d")&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;If you want to convert your date to an epoch time:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;|eval epochdate=strptime(yourdate, "%Y-%m-%d")&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;You can also use relative_time to find the epoch value of 30 days ago:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;|eval epoch30days_ago=relative_time(now(), "-30d@d" )&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;This could be used to do a direct comparison with the strptime value from above.&lt;/P&gt;

&lt;P&gt;Finally, you can do the strptime and set it to _time. This would allow you to set the time range directly:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;|eval _time=strptime(yourdate, "%Y-%m-%d") |search latest=-30d&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:28:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65058#M16086</guid>
      <dc:creator>reed_kelly</dc:creator>
      <dc:date>2020-09-28T12:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a date field with current date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65059#M16087</link>
      <description>&lt;P&gt;I tried with the following lines in my search and it works now.&lt;/P&gt;

&lt;P&gt;eval epochevent=strptime(N_patch, "%Y/%m/%d") | eval epoch30daysago=relative_time(now(), "-30d@d" ) | where epoch30daysago&amp;gt;=epochevent &lt;/P&gt;

&lt;P&gt;Thanks for your help !&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:29:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65059#M16087</guid>
      <dc:creator>rbw78</dc:creator>
      <dc:date>2020-09-28T12:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a date field with current date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65060#M16088</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Thanks for this answer.&lt;BR /&gt;
And how to control if some date and time is after or before a certain date and time (let's say in epoch time)?&lt;/P&gt;

&lt;P&gt;Skender&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2015 14:10:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65060#M16088</guid>
      <dc:creator>skender27</dc:creator>
      <dc:date>2015-09-01T14:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a date field with current date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65061#M16089</link>
      <description>&lt;P&gt;Hi @reed.kelly,&lt;BR /&gt;
How we can get the epoch time for relative time like &lt;A href="mailto:-7d@h"&gt;-7d@h&lt;/A&gt;. &lt;/P&gt;

&lt;P&gt;earliest = -7d@h &lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 17:27:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65061#M16089</guid>
      <dc:creator>twh1</dc:creator>
      <dc:date>2018-09-25T17:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a date field with current date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65062#M16090</link>
      <description>&lt;P&gt;I think that is in my answer. &lt;BR /&gt;
    | makeresults &lt;BR /&gt;
    | fields - _time &lt;BR /&gt;
    | eval seven_days_on_hour=relative_time(now(), "-7d@h" ) &lt;BR /&gt;
Does that answer it?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:22:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65062#M16090</guid>
      <dc:creator>reed_kelly</dc:creator>
      <dc:date>2020-09-29T21:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a date field with current date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65063#M16091</link>
      <description>&lt;P&gt;Hi @reed.kelly ,&lt;BR /&gt;
Yes, we can get this for fixed time. &lt;/P&gt;

&lt;P&gt;I want to check the records for which CREATE_TIME match based on my date selection from time picker control. Currently I am using below query, which is always checking only for  today's date.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=os_na sourcetype="oracle_os:healthcheck" "ADR Home =" | multikv | table HOSTNAME INCIDENT_ID PROBLEM_KEY CREATE_TIME TIMESTAMP | dedup INCIDENT_ID | eval create_day=substr(CREATE_TIME, 1, 10) | eval now_day = strftime(now(), "%m/%d/%Y") | where INCIDENT_ID!=" " AND create_day==now_day
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Could you please help me to get desired result.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 11:58:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65063#M16091</guid>
      <dc:creator>twh1</dc:creator>
      <dc:date>2018-09-26T11:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a date field with current date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65064#M16092</link>
      <description>&lt;P&gt;I have some thoughts, but this question deserves its own top-level question so that others can offer their own insight. Also, people looking for answers to questions like yours will find a more targeted answer. Don't be afraid to open a whole new question &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 13:20:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65064#M16092</guid>
      <dc:creator>reed_kelly</dc:creator>
      <dc:date>2018-09-26T13:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a date field with current date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65065#M16093</link>
      <description>&lt;P&gt;I have posted this as a new question. below is the link.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/689581/how-to-compare-the-log-date-with-time-picker-date.html"&gt;https://answers.splunk.com/answers/689581/how-to-compare-the-log-date-with-time-picker-date.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 17:35:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65065#M16093</guid>
      <dc:creator>twh1</dc:creator>
      <dc:date>2018-09-26T17:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: Compare a date field with current date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65066#M16094</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;I want  to compare the event time to less than Tuesday 2PM of every week, Could you please let me know if this is possible??&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Anilkumar&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 05:15:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65066#M16094</guid>
      <dc:creator>in22915110</dc:creator>
      <dc:date>2020-04-22T05:15:40Z</dc:date>
    </item>
  </channel>
</rss>

