<?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 manipulation in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113044#M183786</link>
    <description>&lt;P&gt;something like this is close&lt;/P&gt;

&lt;P&gt;eval earliest = strptime("09/05/2014:09:01:00" , "%m/%d/%YT%H:%M:%S%z")-604800&lt;/P&gt;

&lt;P&gt;but if I pipe it, then it just evaluates the time but does not limit the search to that time range&lt;/P&gt;

&lt;P&gt;index=uk | eval earliest = strptime("09/05/2014:09:01:00" , "%m/%d/%YT%H:%M:%S%z")-604800&lt;/P&gt;

&lt;P&gt;runs but with no time limit&lt;/P&gt;

&lt;P&gt;The ones below give errors&lt;/P&gt;

&lt;P&gt;index=uk eval earliest = strptime("09/05/2014:09:01:00" , "%m/%d/%YT%H:%M:%S%z")-604800&lt;/P&gt;

&lt;P&gt;index=uk | earliest = strptime("09/05/2014:09:01:00" , "%m/%d/%YT%H:%M:%S%z")-604800&lt;/P&gt;

&lt;P&gt;etc&lt;/P&gt;</description>
    <pubDate>Fri, 05 Sep 2014 14:47:21 GMT</pubDate>
    <dc:creator>stephenmoorhous</dc:creator>
    <dc:date>2014-09-05T14:47:21Z</dc:date>
    <item>
      <title>date manipulation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113042#M183784</link>
      <description>&lt;P&gt;Hi, I have a simple xml form where the user can pass a start and end date and time to a query like&lt;/P&gt;

&lt;P&gt;index=uk earliest=$userStartTime$ latest=$userEndTime$ | etc&lt;/P&gt;

&lt;P&gt;this works fine&lt;/P&gt;

&lt;P&gt;I want a 2nd query which runs for the same times but for a week earlier - I have tried the following&lt;/P&gt;

&lt;P&gt;index=uk earlies=$userStartTime$-1w latest=$userEndTime$-1w | etc&lt;/P&gt;

&lt;P&gt;index=uk | eval earliest=relative_time($userStartTime$,"-1w") | eval latest=relative_time($userEndTime$,"-1w") | etc&lt;/P&gt;

&lt;P&gt;index=uk | myearliest = strptime($userStartTime$, "%m-%d-%YT%H:%M:%S%z") | eval earliest=relative_time(myearliest,"-1w")| mylatest = strptime($userEndTime$, "%m-%d-%YT%H:%M:%S%z") | eval latest=relative_time(mylatest,"-1w") | etc&lt;/P&gt;

&lt;P&gt;but none of these work...&lt;/P&gt;

&lt;P&gt;update - &lt;BR /&gt;
The only working solution I have found so far is to do a search on the time field as per below &lt;/P&gt;

&lt;P&gt;index=uk | eval e=strptime("09/09/2014:14:00:00","%m/%d/%Y:%H:%M:%S") | eval l=strptime("09/09/2014:14:10:00","%m/%d/%Y:%H:%M:%S") | eval e=e-3600 | eval l=l-3600 | convert mktime(_time) as d |where d&amp;gt;e AND d&amp;lt;l | table _time d e l &lt;/P&gt;

&lt;P&gt;This successfully returns all records in the desired time range but has to search the entire data set first - but there must be a way of modifying the earliest and latest search times? &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:30:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113042#M183784</guid>
      <dc:creator>stephenmoorhous</dc:creator>
      <dc:date>2020-09-28T17:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: date manipulation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113043#M183785</link>
      <description>&lt;P&gt;You can try converting your time to epoch time and subtracting 604800 (604800 is number of seconds in a week)&lt;/P&gt;</description>
      <pubDate>Fri, 05 Sep 2014 13:58:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113043#M183785</guid>
      <dc:creator>pradeepkumarg</dc:creator>
      <dc:date>2014-09-05T13:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: date manipulation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113044#M183786</link>
      <description>&lt;P&gt;something like this is close&lt;/P&gt;

&lt;P&gt;eval earliest = strptime("09/05/2014:09:01:00" , "%m/%d/%YT%H:%M:%S%z")-604800&lt;/P&gt;

&lt;P&gt;but if I pipe it, then it just evaluates the time but does not limit the search to that time range&lt;/P&gt;

&lt;P&gt;index=uk | eval earliest = strptime("09/05/2014:09:01:00" , "%m/%d/%YT%H:%M:%S%z")-604800&lt;/P&gt;

&lt;P&gt;runs but with no time limit&lt;/P&gt;

&lt;P&gt;The ones below give errors&lt;/P&gt;

&lt;P&gt;index=uk eval earliest = strptime("09/05/2014:09:01:00" , "%m/%d/%YT%H:%M:%S%z")-604800&lt;/P&gt;

&lt;P&gt;index=uk | earliest = strptime("09/05/2014:09:01:00" , "%m/%d/%YT%H:%M:%S%z")-604800&lt;/P&gt;

&lt;P&gt;etc&lt;/P&gt;</description>
      <pubDate>Fri, 05 Sep 2014 14:47:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113044#M183786</guid>
      <dc:creator>stephenmoorhous</dc:creator>
      <dc:date>2014-09-05T14:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: date manipulation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113045#M183787</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=uk [|gentimes start=-1 | eval earliest=if(match("$userStartTime$","^\d+$"),relative_time("$userStartTime$","-1w"),relative_time(relative_time(now,"$userStartTime$"),"-1w")) | eval latest=if(match("$userEndTime$","^\d+$"),relative_time("$userEndTime$","-1w"),relative_time(relative_time(now,"$userEndTime$"),"-1w")) | table earliest latest] 
| etc
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Sep 2014 18:22:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113045#M183787</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-09-05T18:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: date manipulation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113046#M183788</link>
      <description>&lt;P&gt;hi, i'm sorry but&lt;BR /&gt;
This gives the following warnings&lt;/P&gt;

&lt;P&gt;[subsearch]: No matching fields exist&lt;BR /&gt;
The specified search will not match any events&lt;/P&gt;

&lt;P&gt;I tried removing the&lt;/P&gt;

&lt;P&gt;| table earliest latest&lt;/P&gt;

&lt;P&gt;and that generates the error&lt;/P&gt;

&lt;P&gt;Unable to parse 1410130799 with format: %m/%d/%Y:%H:%M:%S&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2014 13:30:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113046#M183788</guid>
      <dc:creator>stephenmoorhous</dc:creator>
      <dc:date>2014-09-08T13:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: date manipulation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113047#M183789</link>
      <description>&lt;P&gt;The full search is &lt;/P&gt;

&lt;P&gt;index=uk [|gentimes start=-1 | eval earliest=if(match("09/08/2014:12:00:00","^\d+$"),relative_time("09/08/2014:12:00:00","-1w"),relative_time(relative_time(now,"09/08/2014:12:00:00"),"-1w")) | eval latest=if(match("09/08/2014:12:30:00","^\d+$"),relative_time("09/08/2014:12:30:00","-1w"),relative_time(relative_time(now,"09/08/2014:12:30:00"),"-1w")) | table earliest latest]  | top punct&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:30:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113047#M183789</guid>
      <dc:creator>stephenmoorhous</dc:creator>
      <dc:date>2020-09-28T17:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: date manipulation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113048#M183790</link>
      <description>&lt;P&gt;The only working solution I have found so far is to do a search on the time field as per below &lt;/P&gt;

&lt;P&gt;index=uk | eval e=strptime("09/09/2014:14:00:00","%m/%d/%Y:%H:%M:%S") | eval l=strptime("09/09/2014:14:10:00","%m/%d/%Y:%H:%M:%S") | eval e=e-3600 | eval l=l-3600 | convert mktime(_time) as d |where d&amp;gt;e AND d&amp;lt;l | table _time d e l &lt;/P&gt;

&lt;P&gt;This successfully returns all records in the desired time range but has to search the entire data set first - but there must be a way of modifying the earliest and latest search times?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Sep 2014 15:11:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/date-manipulation/m-p/113048#M183790</guid>
      <dc:creator>stephenmoorhous</dc:creator>
      <dc:date>2014-09-09T15:11:11Z</dc:date>
    </item>
  </channel>
</rss>

