<?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: Evaluating and converting dates in search query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Evaluating-and-converting-dates-in-search-query/m-p/170362#M48741</link>
    <description>&lt;P&gt;There are two options that you can try:- &lt;/P&gt;

&lt;P&gt;1) Optimize the subsearch to return the result faster&lt;BR /&gt;
Intead of using &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; search index=os | eval theDay=substr("Aug 10, 2015", 4, 3) | return $theDay 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval theDay=substr("Aug 10, 2015", 4, 3) | return $theDay 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;2) Create a macro for the conversion. [Recommended]&lt;BR /&gt;
Create a macro with following specifications&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Name: getDatePart(2)
Definition: strftime(strptime("$date$","%b %d, %Y"),"%$datepart$")
Arguments: date,datepart
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Usage:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ...  date_mday=`getDatePart("Aug 10, 2015","d")` date_month=`getDatePart("Aug 10, 2015","B")` date_year=`getDatePart("Aug 10, 2015","Y")` ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 13 Aug 2015 15:02:37 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2015-08-13T15:02:37Z</dc:date>
    <item>
      <title>Evaluating and converting dates in search query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Evaluating-and-converting-dates-in-search-query/m-p/170361#M48740</link>
      <description>&lt;P&gt;I have a graph that displays an average value per day over a week as columns. When clicking a specific column a line chart displays how this value averaged over that day. The value passed from the per day-average chart is the date that is clicked and it is then input as a token (in this case "Aug 10, 2015") in the following query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...  date_mday=[ search index=os | eval theDay=substr("Aug 10, 2015", 4, 3) | return $theDay ] date_month=[search index=os | eval theMonth=case(substr("Aug 10, 2015", 1, 3) LIKE "%Jan%", "january", substr("Aug 10, 2015", 1, 3) LIKE "%Feb%", "febuary", substr("Aug 10, 2015", 1, 3) LIKE "%Mar%", "march", substr("Aug 10, 2015", 1, 3) LIKE "%Apr%", "april", substr("Aug 10, 2015", 1, 3) LIKE "%May%", "may", substr("Aug 10, 2015", 1, 3) LIKE "%Jun%", "june", substr("Aug 10, 2015", 1, 3) LIKE "%Jul%", "july", substr("Aug 10, 2015", 1, 3) LIKE "%Aug%", "august", substr("Aug 10, 2015", 1, 3) LIKE "%Sep%", "september", substr("Aug 10, 2015", 1, 3) LIKE "%Oct%", "october", substr("Aug 10, 2015", 1, 3) LIKE "%Nov%", "november", substr("Aug 10, 2015", 1, 3) LIKE "%Dec%", "december") | return $theMonth ] date_year=[ search index=os | eval theYear=substr("Aug 10, 2015", 8, 5) | return $theYear ] ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As you can see the query evaluates the day and "converts" it to date numbers that are possible to use the search with. This works but of takes A LOT of time to execute, using a subsearch as an excuse to evaluate a "local" token is ugly and of course very time consuming. Is there any other way of doing this, either by adjusting the query or using a completely different method? &lt;/P&gt;

&lt;P&gt;I should mention that installing any additional apps etcetera is for various reasons not an option, the solution needs to applicable with a vanilla Splunk instance. I also do not want to change the dateformat as I want to keep it as "human readable" as possible (lol).&lt;/P&gt;

&lt;P&gt;Tricky!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 14:40:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Evaluating-and-converting-dates-in-search-query/m-p/170361#M48740</guid>
      <dc:creator>ohlafl</dc:creator>
      <dc:date>2015-08-13T14:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Evaluating and converting dates in search query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Evaluating-and-converting-dates-in-search-query/m-p/170362#M48741</link>
      <description>&lt;P&gt;There are two options that you can try:- &lt;/P&gt;

&lt;P&gt;1) Optimize the subsearch to return the result faster&lt;BR /&gt;
Intead of using &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; search index=os | eval theDay=substr("Aug 10, 2015", 4, 3) | return $theDay 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval theDay=substr("Aug 10, 2015", 4, 3) | return $theDay 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;2) Create a macro for the conversion. [Recommended]&lt;BR /&gt;
Create a macro with following specifications&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Name: getDatePart(2)
Definition: strftime(strptime("$date$","%b %d, %Y"),"%$datepart$")
Arguments: date,datepart
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Usage:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ...  date_mday=`getDatePart("Aug 10, 2015","d")` date_month=`getDatePart("Aug 10, 2015","B")` date_year=`getDatePart("Aug 10, 2015","Y")` ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Aug 2015 15:02:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Evaluating-and-converting-dates-in-search-query/m-p/170362#M48741</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-08-13T15:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Evaluating and converting dates in search query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Evaluating-and-converting-dates-in-search-query/m-p/170363#M48742</link>
      <description>&lt;P&gt;Thank you, both solutions worked perfectly.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2015 11:24:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Evaluating-and-converting-dates-in-search-query/m-p/170363#M48742</guid>
      <dc:creator>ohlafl</dc:creator>
      <dc:date>2015-08-17T11:24:44Z</dc:date>
    </item>
  </channel>
</rss>

