<?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: Previous month search based on now in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529375#M149496</link>
    <description>&lt;P&gt;The "&lt;FONT face="courier new,courier"&gt;@mon&lt;/FONT&gt;" argument means "the beginning of the current month", which is 1st Nov in our context.&amp;nbsp; So, when the SPL says "&lt;FONT face="courier new,courier"&gt;aca_epoch &amp;lt; relative_time(now(), "@mon")&lt;/FONT&gt;" it's accepting dates up to 31 Oct 2020 23:59:59.&amp;nbsp; That's what's desired, right?&lt;/P&gt;</description>
    <pubDate>Fri, 13 Nov 2020 21:34:00 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2020-11-13T21:34:00Z</dc:date>
    <item>
      <title>Previous month search based on now</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529334#M149483</link>
      <description>&lt;P&gt;Hi everyone,&lt;BR /&gt;I'm new to Splunk and trying to create a simple report, but I'm already having trouble.&lt;BR /&gt;I would like to do a search on a DATA_ACA field that contains dates in this format: 2020-11-13 15:10:23.&lt;BR /&gt;The search must return all those events that have the previous month in the DATA_ACA field, therefore all the events that have: 2020-10- *&lt;/P&gt;&lt;P&gt;I tried with&lt;BR /&gt;index=........&lt;BR /&gt;| eval month_aca = strptime (relative_time (now (), "- 1mon @ d") "% m)&lt;BR /&gt;| eval year_aca = strptime (relative_time (now (), "- 1mon @ d") "% Y)&lt;BR /&gt;| eval data_aca = year_aca. "-". month_aca. "- *"&lt;BR /&gt;| search DATA_ACA = data_aca&lt;BR /&gt;.....&lt;/P&gt;&lt;P&gt;....&lt;BR /&gt;| table DATA_ACA, month_aca, year_aca, data_aca&lt;/P&gt;&lt;P&gt;but nothing returns me no event.&lt;BR /&gt;You can help me?&lt;/P&gt;&lt;P&gt;Do you have any suggestions ?&lt;BR /&gt;Tks&lt;BR /&gt;Bye&lt;BR /&gt;Antonio&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 17:20:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529334#M149483</guid>
      <dc:creator>antonio147</dc:creator>
      <dc:date>2020-11-13T17:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Previous month search based on now</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529360#M149490</link>
      <description>&lt;P&gt;Try converting DATA_ACA into epoch form and then comparing it to the first and last days of the month.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=foo
| eval aca_epoch = strptime(DATA_ACA, "%Y-%m-%d")
| where (aca_epoch &amp;gt;= relative_time(now(), "-1mon@mon")
  AND aca_epoch &amp;lt; relative_time(now(), "@mon"))
| table DATA_ACA&lt;/LI-CODE&gt;&lt;P&gt;If you want to keep the current query, be aware that the &lt;FONT face="courier new,courier"&gt;search&lt;/FONT&gt; command treats the RHS as a string.&amp;nbsp; Use the &lt;FONT face="courier new,courier"&gt;where&lt;/FONT&gt; command to compare a field to another field.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=........
| eval month_aca = strptime (relative_time (now (), "- 1mon @ d") "% m)
| eval year_aca = strptime (relative_time (now (), "- 1mon @ d") "% Y)
| eval data_aca = year_aca. "-". month_aca. "- *"
| where DATA_ACA = 'data_aca'
.....

....
| table DATA_ACA, month_aca, year_aca, data_aca&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 20:05:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529360#M149490</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-11-13T20:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Previous month search based on now</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529368#M149493</link>
      <description>&lt;P&gt;Hi richgalloway,&lt;BR /&gt;Thanks for the reply.&lt;BR /&gt;A doubt, if I use your suggestion converting to epoch, if now is for example November 12th, where would it take from October 12th to November 11th correct?&lt;BR /&gt;I need to extract all the October events from 1st to 31st, without any November day.&lt;BR /&gt;So for each month, on any day I launch the query, I always have to take only all the days of the previous month.&lt;/P&gt;&lt;P&gt;In any case, thanks, tomorrow I will try your suggestions and let you know the outcome.&lt;BR /&gt;Bye&lt;BR /&gt;Antonio&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 20:35:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529368#M149493</guid>
      <dc:creator>antonio147</dc:creator>
      <dc:date>2020-11-13T20:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Previous month search based on now</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529375#M149496</link>
      <description>&lt;P&gt;The "&lt;FONT face="courier new,courier"&gt;@mon&lt;/FONT&gt;" argument means "the beginning of the current month", which is 1st Nov in our context.&amp;nbsp; So, when the SPL says "&lt;FONT face="courier new,courier"&gt;aca_epoch &amp;lt; relative_time(now(), "@mon")&lt;/FONT&gt;" it's accepting dates up to 31 Oct 2020 23:59:59.&amp;nbsp; That's what's desired, right?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 21:34:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529375#M149496</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-11-13T21:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Previous month search based on now</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529416#M149520</link>
      <description>&lt;P&gt;Hi richgalloway,&lt;BR /&gt;your suggestion was very valuable,&lt;BR /&gt;with the where and with&lt;BR /&gt;| eval aca_epoch = strptime (DATA_ACA, "% Y-% m-% d")&lt;BR /&gt;| where (aca_epoch&amp;gt; = relative_time (now (), "-1mon @ mon")&lt;BR /&gt;AND aca_epoch &amp;lt;relative_time (now (), "@mon"))&lt;BR /&gt;it worked the first time.&lt;BR /&gt;Also thanks for your explanations, I did not know that @mon took the first day of the month, I thought it was only referring to the number of days / months back or forward.&lt;BR /&gt;I understood that the search refers to strings while the where to the content of a field.&lt;BR /&gt;I have a question to ask: what is the difference between where and search if both are used as a comparison?&lt;BR /&gt;soo for the above or is there more?&lt;/P&gt;&lt;P&gt;and if instead of now (), I wanted to use a date of my choice, how should I put it?&lt;BR /&gt;Just replace now () with "2020-09-27" for example?&lt;BR /&gt;Thanks again for the tip&lt;BR /&gt;a nice we&lt;BR /&gt;Antonio&lt;/P&gt;</description>
      <pubDate>Sat, 14 Nov 2020 15:04:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529416#M149520</guid>
      <dc:creator>antonio147</dc:creator>
      <dc:date>2020-11-14T15:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: Previous month search based on now</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529417#M149521</link>
      <description>&lt;P&gt;yes and just that&lt;BR /&gt;Thank you so much&lt;/P&gt;</description>
      <pubDate>Sat, 14 Nov 2020 14:52:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Previous-month-search-based-on-now/m-p/529417#M149521</guid>
      <dc:creator>antonio147</dc:creator>
      <dc:date>2020-11-14T14:52:33Z</dc:date>
    </item>
  </channel>
</rss>

