<?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 Range Search on DateTime Field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82717#M21004</link>
    <description>&lt;P&gt;Hi, I have a field which contains a DateTime. I want to be able to search between a range of Dates on this as opposed to _time.&lt;/P&gt;

&lt;P&gt;Example log:&lt;BR /&gt;
2012-06-25 07:17:19.6676 Action="DALCacheInsert" ... Date="28/06/2012 23:00:00" ...&lt;/P&gt;

&lt;P&gt;I want to be able to search Date&amp;gt;"28/06/2012 00:00:00"&lt;/P&gt;</description>
    <pubDate>Mon, 25 Jun 2012 08:51:52 GMT</pubDate>
    <dc:creator>matthewcanty</dc:creator>
    <dc:date>2012-06-25T08:51:52Z</dc:date>
    <item>
      <title>Date Range Search on DateTime Field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82717#M21004</link>
      <description>&lt;P&gt;Hi, I have a field which contains a DateTime. I want to be able to search between a range of Dates on this as opposed to _time.&lt;/P&gt;

&lt;P&gt;Example log:&lt;BR /&gt;
2012-06-25 07:17:19.6676 Action="DALCacheInsert" ... Date="28/06/2012 23:00:00" ...&lt;/P&gt;

&lt;P&gt;I want to be able to search Date&amp;gt;"28/06/2012 00:00:00"&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2012 08:51:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82717#M21004</guid>
      <dc:creator>matthewcanty</dc:creator>
      <dc:date>2012-06-25T08:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: Date Range Search on DateTime Field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82718#M21005</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Have you looked at the &lt;CODE&gt;strptime&lt;/CODE&gt; function for &lt;CODE&gt;eval&lt;/CODE&gt;? This will let you create a new field in which you convert your Date string to epoch. I don't believe you can perform operations like greater-than or less-than directly on strings like your Date.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval blah = strptime(Date, "%d/%m/%Y %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Unfortunately this requires you to specify your time constraints in epoch which is not as easy as one would like. However, you can do the same trick again in the search, so that it reads;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| eval mylimit=strptime("24 Jun 2012 23:52:55","%d %b %Y %H:%M:%S")
| eval blah = strptime(Date, "%d/%m/%Y %H:%M:%S")
| where blah &amp;lt; mylimit
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As you can see there are different date patterns used, and you can use whichever you like AS LONG AS the strptime pattern matches the string. The format of the date string is already set in the event, so the pattern for that is set, but the date string used for mylimit is determined by you, so you can use any format you like, just make sure that the pattern (i.e. "%Y %m %d" etc etc) matches.&lt;/P&gt;

&lt;P&gt;If you don't want to complicate things, use the same for both Date and mylimit, and write your mylimit string accordingly.&lt;/P&gt;

&lt;P&gt;For more information see;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://strftime.org/"&gt;http://strftime.org/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/5.0/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;UPDATE:&lt;/P&gt;

&lt;P&gt;The string and pattern within the strptime function must match in order for this to make sense:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;string           pattern
22Apr2004        %d%b%Y
2001-11-14       %Y-%m-%d
Dec 24, 1988     %b %d, %Y
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you do not specify a time part of the string and pattern, the start of the day will be used (00:00:00), so your search from the 26th to the 30th would not include any events from the 30th.&lt;/P&gt;

&lt;P&gt;Also, I'm not sure that you should use &lt;CODE&gt;earliest&lt;/CODE&gt; and &lt;CODE&gt;latest&lt;/CODE&gt;, since they are reserved words in splunk, and will act as constraints on _time.&lt;/P&gt;

&lt;P&gt;Hope this helps,&lt;/P&gt;

&lt;P&gt;/Kristian&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2012 09:28:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82718#M21005</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-06-25T09:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Date Range Search on DateTime Field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82719#M21006</link>
      <description>&lt;P&gt;Okay so when I do this:&lt;/P&gt;

&lt;P&gt;host="APP3018-TSDAL"&lt;BR /&gt;
| eval earliest = strptime("26 Jun 2012","%d%b%Y %H:%M:%S") &lt;BR /&gt;
| eval latest = strptime("30 Jun 2012","%d%b%Y %H:%M:%S")&lt;BR /&gt;
| eval date = strptime(Date, "%d/%m/%Y %H:%M:%S")&lt;BR /&gt;
| search date &amp;gt; earliest AND date &amp;lt; latest&lt;/P&gt;

&lt;P&gt;I should be getting some results between 26th and 30th June - there are definitely some. However it is returning nothing.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2012 09:46:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82719#M21006</guid>
      <dc:creator>matthewcanty</dc:creator>
      <dc:date>2012-06-25T09:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: Date Range Search on DateTime Field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82720#M21007</link>
      <description>&lt;P&gt;see update above. &lt;BR /&gt;
/k&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2012 10:06:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82720#M21007</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-06-25T10:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: Date Range Search on DateTime Field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82721#M21008</link>
      <description>&lt;P&gt;Still nothing. Search:&lt;/P&gt;

&lt;P&gt;host="APP3018-TSDAL" &lt;BR /&gt;
| eval e=strptime("1/1/2012","%d/%m/%Y") &lt;BR /&gt;
| eval l=strptime("1/1/2013","%d/%m/%Y") &lt;BR /&gt;
| eval d=strptime(Date, "%D/%M/%Y %H:%M:%S") &lt;BR /&gt;
| search d&amp;gt;e AND d&amp;lt;l&lt;/P&gt;

&lt;P&gt;Example expected event/result:&lt;/P&gt;

&lt;P&gt;2012-06-25 11:29:00.4658 Action="DALCacheUpdate" Id="251234055" Description="Degerfors v Trelleborgs" SportId="Football" CompetitionId="Superettan" Date="25/06/2012 17:59:00" Source="..."&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2012 10:31:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82721#M21008</guid>
      <dc:creator>matthewcanty</dc:creator>
      <dc:date>2012-06-25T10:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: Date Range Search on DateTime Field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82722#M21009</link>
      <description>&lt;P&gt;Hmm, I just tested that, and it didn't work for me either, until I changed the last &lt;CODE&gt;search&lt;/CODE&gt; expression to a &lt;CODE&gt;where&lt;/CODE&gt;;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| where (d &amp;gt; e) AND (d &amp;lt; l) &lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Don't know why, I thought they would work the same here.&lt;/P&gt;

&lt;P&gt;/k&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2012 11:04:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-Range-Search-on-DateTime-Field/m-p/82722#M21009</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-06-25T11:04:31Z</dc:date>
    </item>
  </channel>
</rss>

