<?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 edit my search to compare two dates? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-compare-two-dates/m-p/202437#M58725</link>
    <description>&lt;P&gt;I am assuming when you are comparing greater than or less than you mean epochNumber of _time is greater/less than epoch number of "2016-01-01".  Give this a try please and adjust greater than or less than according to your like in eval status1 command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yourBaseSearch to get the _time
|eval myNewTime=strptime("2016-01-01", "%Y-%m-%d")
| eval time1=strftime(_time, "%Y-%m-%d")
| eval epoch_time=strptime( time1, "%Y-%m-%d")
| eval status1=case( epoch_time &amp;lt; myNewTime, "Yes", 1=1, "No" )
| table _time, epoch_time, myNewTime, status1, Name, Rank
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 02 Nov 2016 04:00:09 GMT</pubDate>
    <dc:creator>gokadroid</dc:creator>
    <dc:date>2016-11-02T04:00:09Z</dc:date>
    <item>
      <title>How to edit my search to compare two dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-compare-two-dates/m-p/202436#M58724</link>
      <description>&lt;P&gt;I want to compare two dates using case statement&lt;BR /&gt;
Theoretically, case( _time &amp;gt; "2016-01-01") . If True, Print "Yes" in New column status1&lt;/P&gt;

&lt;P&gt;Below is the search, but I am not getting any results. Can you please help?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="test4" sourcetype="test2" | convert timeformat="%Y-%m-%d" ctime(_time) AS c_time | eval status1 = case(c_time &amp;lt; strptime(strptime("2016-01-01","%Y-%m-%d"),"%Y-%m-%d") , "Yes") |table _time, c_time,  Status1 , Name, Rank
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note: I'm using &lt;CODE&gt;strptime&lt;/CODE&gt; twice to convey from epoch.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 03:09:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-compare-two-dates/m-p/202436#M58724</guid>
      <dc:creator>splunk_hvijay</dc:creator>
      <dc:date>2016-11-02T03:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to compare two dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-compare-two-dates/m-p/202437#M58725</link>
      <description>&lt;P&gt;I am assuming when you are comparing greater than or less than you mean epochNumber of _time is greater/less than epoch number of "2016-01-01".  Give this a try please and adjust greater than or less than according to your like in eval status1 command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yourBaseSearch to get the _time
|eval myNewTime=strptime("2016-01-01", "%Y-%m-%d")
| eval time1=strftime(_time, "%Y-%m-%d")
| eval epoch_time=strptime( time1, "%Y-%m-%d")
| eval status1=case( epoch_time &amp;lt; myNewTime, "Yes", 1=1, "No" )
| table _time, epoch_time, myNewTime, status1, Name, Rank
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Nov 2016 04:00:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-compare-two-dates/m-p/202437#M58725</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2016-11-02T04:00:09Z</dc:date>
    </item>
  </channel>
</rss>

