<?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: Eval if date stamp is a certain month? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296697#M89511</link>
    <description>&lt;P&gt;Where does my current date+time stamp go in this? Also how do I specify what month I am looking for?&lt;/P&gt;</description>
    <pubDate>Thu, 29 Mar 2018 18:24:20 GMT</pubDate>
    <dc:creator>rkassabov</dc:creator>
    <dc:date>2018-03-29T18:24:20Z</dc:date>
    <item>
      <title>Eval if date stamp is a certain month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296691#M89505</link>
      <description>&lt;P&gt;I need to eval if a date+time stamp  (for example: 2018-02-22 21:54:00.380000) falls in a certain month (i.e. jan, feb, etc).&lt;/P&gt;

&lt;P&gt;If so, I need to write data to a column of my creation, how would I accomplish this?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 05:33:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296691#M89505</guid>
      <dc:creator>rkassabov</dc:creator>
      <dc:date>2018-03-29T05:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Eval if date stamp is a certain month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296692#M89506</link>
      <description>&lt;P&gt;Try this, I took &lt;CODE&gt;_time&lt;/CODE&gt; and convert to epoch time from there I can able to eval my month &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Yoursearch| eval new_date_epoch=_time|eval month=strftime(new_date_epoch,"%b")|table _time,new_date_epoch,month,_raw
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Mar 2018 06:02:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296692#M89506</guid>
      <dc:creator>splunker12er</dc:creator>
      <dc:date>2018-03-29T06:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: Eval if date stamp is a certain month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296693#M89507</link>
      <description>&lt;P&gt;Hey@rkassabov,&lt;/P&gt;

&lt;P&gt;You can try using the default splunk field "date_month"&lt;BR /&gt;
So your query should be like:&lt;BR /&gt;
index=.. | stats ... by date_month&lt;/P&gt;

&lt;P&gt;Let me know if this helps!!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:49:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296693#M89507</guid>
      <dc:creator>deepashri_123</dc:creator>
      <dc:date>2020-09-29T18:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Eval if date stamp is a certain month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296694#M89508</link>
      <description>&lt;P&gt;Are you looking for writing a case expression to set value based on month of the timestamp (assuming _time is the field)? If yes, you can do like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
|eval month=strftime(new_date_epoch,"%b")
| eval ColOfYourCreation=case(month="jan","Specific to Jan value", month="feb","Specific to Feb value",....., true(),"Some Default value")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Mar 2018 09:36:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296694#M89508</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-03-29T09:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Eval if date stamp is a certain month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296695#M89509</link>
      <description>&lt;P&gt;Where does my current date+time stamp go in this? Also how do I specify what month I am looking for?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 18:23:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296695#M89509</guid>
      <dc:creator>rkassabov</dc:creator>
      <dc:date>2018-03-29T18:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: Eval if date stamp is a certain month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296696#M89510</link>
      <description>&lt;P&gt;Where does my current date+time stamp go in this? Also how do I specify what month I am looking for?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 18:23:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296696#M89510</guid>
      <dc:creator>rkassabov</dc:creator>
      <dc:date>2018-03-29T18:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Eval if date stamp is a certain month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296697#M89511</link>
      <description>&lt;P&gt;Where does my current date+time stamp go in this? Also how do I specify what month I am looking for?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 18:24:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296697#M89511</guid>
      <dc:creator>rkassabov</dc:creator>
      <dc:date>2018-03-29T18:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Eval if date stamp is a certain month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296698#M89512</link>
      <description>&lt;P&gt;Hey Rkassabov,&lt;/P&gt;

&lt;P&gt;Try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your search | eval currentmonth=relative_time(now(), "@mon") | eval previousmonth=relative_time(now(),"-1mon@mon") | 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In your case you can use whatever field generates 2018-02-22 21:54:00.380000 and have eval convert it to a month and then use more evals to do the math.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/290050/how-to-extract-month-from-a-date-field-and-sort-by.html"&gt;https://answers.splunk.com/answers/290050/how-to-extract-month-from-a-date-field-and-sort-by.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Or you can try converting the date field into Epoch Time, which I found much easier to work with.&lt;/P&gt;

&lt;P&gt;For example, I wanted to see only tickets from the previous month in my ticketing system (however my resolved_at field was hard to work with so I converted it to epoch time):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Rtime=strptime(resolved_at, "%Y-%m-%d %H:%M:%S") | eval end=relative_time(now(), "@mon") | eval start=relative_time(now(),"-1mon@mon") |  where Rtime &amp;lt;= end AND Rtime &amp;gt;= start AND _time &amp;lt;= end AND _time &amp;gt;= start |
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Mar 2018 22:16:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296698#M89512</guid>
      <dc:creator>hos_2</dc:creator>
      <dc:date>2018-03-29T22:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Eval if date stamp is a certain month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296699#M89513</link>
      <description>&lt;P&gt;The &lt;CODE&gt;|eval month=strftime(new_date_epoch,"%b")&lt;/CODE&gt; portion is where you'd specify our date+timestamp field. If you date+timestamp is a single field with value already in epoch format, just specify the field name there. If it's in string format, then you'd need to convert it to epoch within that expression, like &lt;CODE&gt;|eval month=strftime(strptime(YourTimestampFieldHere,"TimestampFormatWillComeHere"),"%b")&lt;/CODE&gt;. The eval-case expression is where you match month and assign specific value.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 23:42:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296699#M89513</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-03-29T23:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Eval if date stamp is a certain month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296700#M89514</link>
      <description>&lt;P&gt;I still don't understand. In the first example, how would I only perform an operation if the month in the datestamp is march?&lt;/P&gt;

&lt;P&gt;I get that I have to convert the datestamp to make it easier to work with, but how do I check if that new epoch time is the first, second, third etc month of the year, then perform an operation?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 02:38:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296700#M89514</guid>
      <dc:creator>rkassabov</dc:creator>
      <dc:date>2018-03-30T02:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Eval if date stamp is a certain month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296701#M89515</link>
      <description>&lt;P&gt;It looks like you are comparing the datestamp to the current time and looking to see if it was in the previous month.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 03:10:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296701#M89515</guid>
      <dc:creator>rkassabov</dc:creator>
      <dc:date>2018-03-30T03:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: Eval if date stamp is a certain month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296702#M89516</link>
      <description>&lt;P&gt;Hey, so the below eval will run against the current time, then extract the current month and label it as currentmonth:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval currentmonth=relative_time(now(), "@mon") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For example "currentmonth" returns this value today: 1522562400.000000&lt;/P&gt;

&lt;P&gt;Put that into a website like this : &lt;A href="https://www.epochconverter.com/"&gt;https://www.epochconverter.com/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Then you have a epoch time that Splunk created for the begining of the month: GMT: Sunday, April 1, 2018 6:00:00 AM&lt;/P&gt;

&lt;P&gt;Then the @mon part of the search, extracts specifically the month from the currently time.&lt;/P&gt;

&lt;P&gt;You could easily tweak this to do the same to which ever field is generating your date and time.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    | eval new_date=strftime(strptime(&amp;lt;yourfield&amp;gt;, "%Y-%m-%d %H:%M:%S"),"%m")
## This will convert your field into epoch time. Then you could use something like below to tell your search which month you are looking for.
| eval end=relative_time(now(), "@mon") | eval start=relative_time(now(),"-1mon@mon") 
|  where new_date &amp;lt;= end AND new_date &amp;gt;= start AND _time &amp;lt;= end AND _time &amp;gt;= start |
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Apr 2018 14:53:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-if-date-stamp-is-a-certain-month/m-p/296702#M89516</guid>
      <dc:creator>hos_2</dc:creator>
      <dc:date>2018-04-02T14:53:42Z</dc:date>
    </item>
  </channel>
</rss>

