<?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: Date comparison with if statements in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51235#M12362</link>
    <description>&lt;P&gt;great, that helped a lot. I'm using &lt;CODE&gt;len&lt;/CODE&gt; now and I also had to move the if statements before the date comparison for the &lt;CODE&gt;startDateFrom&lt;/CODE&gt; and &lt;CODE&gt;startDateTo&lt;/CODE&gt; to be available&lt;/P&gt;</description>
    <pubDate>Fri, 30 Aug 2013 09:56:15 GMT</pubDate>
    <dc:creator>mcamilleri</dc:creator>
    <dc:date>2013-08-30T09:56:15Z</dc:date>
    <item>
      <title>Date comparison with if statements</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51231#M12358</link>
      <description>&lt;P&gt;I need to use an if statement to set the dates in &lt;CODE&gt;startDateFrom&lt;/CODE&gt; and &lt;CODE&gt;startDateTo&lt;/CODE&gt; if not specified in the &lt;CODE&gt;selectedStartDateFrom&lt;/CODE&gt; and &lt;CODE&gt;selectedStartDateTo&lt;/CODE&gt; variables.&lt;/P&gt;

&lt;P&gt;I then want to use &lt;CODE&gt;startDateFrom&lt;/CODE&gt; and &lt;CODE&gt;startDateTo&lt;/CODE&gt; to filter for entries with &lt;CODE&gt;Experiment_Instance_Start_Date&lt;/CODE&gt; between &lt;CODE&gt;startDateFrom&lt;/CODE&gt; and &lt;CODE&gt;startDateTo&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;The date comparison works fine, it's only when I add the if statements that it stops working. Any ideas what I'm doing wrong here?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval compare=strptime(Experiment_Instance_Start_Date,"%m/%d/%Y") 
| where compare&amp;gt;=strptime(startDateFrom,"%m/%d/%Y")
| eval compare=strptime(startDateTo,"%m/%d/%Y")
| where compare&amp;gt;=strptime(Experiment_Instance_Start_Date,"%m/%d/%Y")
| eval startDateFrom=if("$selectedStartDateFrom$"="", "01/01/1970", "$selectedStartDateFrom$")
| eval startDateTo=if("$selectedStartDateTo$"="", "01/01/2100", "$selectedStartDateTo$")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Aug 2013 15:13:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51231#M12358</guid>
      <dc:creator>mcamilleri</dc:creator>
      <dc:date>2013-08-29T15:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Date comparison with if statements</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51232#M12359</link>
      <description>&lt;P&gt;Are selectedStartDateFrom and selectedStartDateTo &lt;EM&gt;fields&lt;/EM&gt; from your data, or &lt;EM&gt;tokens&lt;/EM&gt;, as provided from a form? The syntax of your if will vary depending upon the answer.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2013 17:01:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51232#M12359</guid>
      <dc:creator>sowings</dc:creator>
      <dc:date>2013-08-29T17:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Date comparison with if statements</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51233#M12360</link>
      <description>&lt;P&gt;They're tokens provided from a form&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2013 17:56:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51233#M12360</guid>
      <dc:creator>mcamilleri</dc:creator>
      <dc:date>2013-08-29T17:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: Date comparison with if statements</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51234#M12361</link>
      <description>&lt;P&gt;Looks like you are doing a string comparison rather than a date comparison. The double quotes around your $selectedStartDateFrom$ convert it to a string.&lt;/P&gt;

&lt;P&gt;In string comparisons you need a == comparison rather than an = comparison: "$selectedStartDateFrom$"==""&lt;/P&gt;

&lt;P&gt;If this doesn't work, you could also do something like: len("$selectedStartDateFrom$")&amp;gt;0&lt;/P&gt;

&lt;P&gt;hope this helps&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2013 20:48:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51234#M12361</guid>
      <dc:creator>aholzer</dc:creator>
      <dc:date>2013-08-29T20:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Date comparison with if statements</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51235#M12362</link>
      <description>&lt;P&gt;great, that helped a lot. I'm using &lt;CODE&gt;len&lt;/CODE&gt; now and I also had to move the if statements before the date comparison for the &lt;CODE&gt;startDateFrom&lt;/CODE&gt; and &lt;CODE&gt;startDateTo&lt;/CODE&gt; to be available&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2013 09:56:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51235#M12362</guid>
      <dc:creator>mcamilleri</dc:creator>
      <dc:date>2013-08-30T09:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Date comparison with if statements</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51236#M12363</link>
      <description>&lt;P&gt;As &lt;EM&gt;aholzer&lt;/EM&gt; said in the comments above, &lt;CODE&gt;"$selectedStartDateFrom$"=""&lt;/CODE&gt; is wrong, so I changed that to &lt;CODE&gt;len("$selectedStartDateFrom$")&amp;gt;0&lt;/CODE&gt;. I also needed to move the &lt;CODE&gt;if&lt;/CODE&gt; statements to before the date comparison for the &lt;CODE&gt;startDateFrom&lt;/CODE&gt; and &lt;CODE&gt;startDateTo&lt;/CODE&gt; to be available. Also start date of &lt;CODE&gt;01/01/1970&lt;/CODE&gt; returns no results, so I changed it to a later date.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval startDateFrom=if(len("$selectedStartDateFrom$")&amp;gt;0, "$selectedStartDateFrom$", "01/01/2000")
| eval startDateTo=if(len("$selectedStartDateTo$")&amp;gt;0, "$selectedStartDateTo$", "01/01/2099")
| eval compare=strptime(Experiment_Instance_Start_Date,"%m/%d/%Y") 
| where compare&amp;gt;=strptime(startDateFrom,"%m/%d/%Y")
| eval compare=strptime(startDateTo,"%m/%d/%Y")
| where compare&amp;gt;=strptime(Experiment_Instance_Start_Date,"%m/%d/%Y")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Aug 2013 10:16:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-comparison-with-if-statements/m-p/51236#M12363</guid>
      <dc:creator>mcamilleri</dc:creator>
      <dc:date>2013-08-30T10:16:01Z</dc:date>
    </item>
  </channel>
</rss>

