<?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 How to extract month from a date field and sort by this without using the _time timestamp? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143585#M39891</link>
    <description>&lt;P&gt;Hi all, I'm a bit new to Splunk - I'm trying to sort some data by month, but I'm running into some roadblocks doing so. I'd like to create a separate field, "month", based on the month value in a field called "date" with format "YYYY/MM/DD HH:MM:SS". I've tried &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   *code* |  eval month = strftime(date,"%m") | stats sum(field1) by field2, field3, month
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but it doesn't seem to be working for this format, as the "month" field shows up blank for all results and I get no results when trying to sort by this field. However, when I try to reorganize the date itself into a different format, it works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; *code* | eval new_date=strftime(strptime(date,"%Y/%m/%d"),"%m/%d/%y") | stats sum(field1) by field2, field3, new_date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And the output is as expected, with the information sorted by relevant fields and the new_date field formatted as MM/DD/YY. &lt;/P&gt;

&lt;P&gt;Any thoughts on how I can do something similar and just get either "01" or "January" as the month field output?&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jul 2015 19:21:17 GMT</pubDate>
    <dc:creator>atammana_splunk</dc:creator>
    <dc:date>2015-07-24T19:21:17Z</dc:date>
    <item>
      <title>How to extract month from a date field and sort by this without using the _time timestamp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143585#M39891</link>
      <description>&lt;P&gt;Hi all, I'm a bit new to Splunk - I'm trying to sort some data by month, but I'm running into some roadblocks doing so. I'd like to create a separate field, "month", based on the month value in a field called "date" with format "YYYY/MM/DD HH:MM:SS". I've tried &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   *code* |  eval month = strftime(date,"%m") | stats sum(field1) by field2, field3, month
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but it doesn't seem to be working for this format, as the "month" field shows up blank for all results and I get no results when trying to sort by this field. However, when I try to reorganize the date itself into a different format, it works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; *code* | eval new_date=strftime(strptime(date,"%Y/%m/%d"),"%m/%d/%y") | stats sum(field1) by field2, field3, new_date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And the output is as expected, with the information sorted by relevant fields and the new_date field formatted as MM/DD/YY. &lt;/P&gt;

&lt;P&gt;Any thoughts on how I can do something similar and just get either "01" or "January" as the month field output?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2015 19:21:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143585#M39891</guid>
      <dc:creator>atammana_splunk</dc:creator>
      <dc:date>2015-07-24T19:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract month from a date field and sort by this without using the _time timestamp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143586#M39892</link>
      <description>&lt;P&gt;if you are wanting to extract month from event time, Splunk already does this for you by storing the month in date_month field.&lt;BR /&gt;
if it's another time field you are working with, you need to make sure you convert your time into epoch time before extracting the month, like you are doing in the second example. &lt;/P&gt;

&lt;P&gt;Try: new_date=strftime(strptime(date,"%Y/%m/%d"),"%m")&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2015 20:22:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143586#M39892</guid>
      <dc:creator>mreynov_splunk</dc:creator>
      <dc:date>2015-07-24T20:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract month from a date field and sort by this without using the _time timestamp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143587#M39893</link>
      <description>&lt;P&gt;Your first attempt failed because &lt;CODE&gt;date&lt;/CODE&gt; field is not an epoch timestamp.&lt;/P&gt;

&lt;P&gt;You should be able to use the standard &lt;CODE&gt;date_month&lt;/CODE&gt; field.  That will give you the name of the month in which the event occurred.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2015 20:23:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143587#M39893</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-07-24T20:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract month from a date field and sort by this without using the _time timestamp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143588#M39894</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; *code* | eval new_date=strftime(strptime(date,"%Y/%m/%d"),"%m") | stats sum(field1) by field2, field3, new_date
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jul 2015 21:26:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143588#M39894</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-07-24T21:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract month from a date field and sort by this without using the _time timestamp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143589#M39895</link>
      <description>&lt;P&gt;Worked like a charm. Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2015 16:56:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143589#M39895</guid>
      <dc:creator>atammana_splunk</dc:creator>
      <dc:date>2015-07-27T16:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract month from a date field and sort by this without using the _time timestamp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143590#M39896</link>
      <description>&lt;P&gt;Note that Splunk does not always do this. I got here because I have an event type that never includes the date_* fields. I'm sure there is a technical reason, but I don't know what it is yet and need to extract the month because Splunk is not doing so.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 05:51:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143590#M39896</guid>
      <dc:creator>n5zap</dc:creator>
      <dc:date>2018-02-04T05:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract month from a date field and sort by this without using the _time timestamp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143591#M39897</link>
      <description>&lt;P&gt;I downvoted this post because it is not always the case that splunk automatically extracts the date_* fields.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 05:52:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-month-from-a-date-field-and-sort-by-this-without/m-p/143591#M39897</guid>
      <dc:creator>n5zap</dc:creator>
      <dc:date>2018-02-04T05:52:30Z</dc:date>
    </item>
  </channel>
</rss>

