<?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: how to extract month date and year and save in a new field from _time in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388155#M113182</link>
    <description>&lt;P&gt;hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/201110"&gt;@niketn&lt;/a&gt;&lt;/P&gt;

&lt;P&gt;The data does not have  date_mday, date_month, date_year  that is why I am using regex to save it as  a new field called date for &lt;/P&gt;

&lt;P&gt;_time=2018-05-10 09:33:54&lt;/P&gt;

&lt;P&gt;|rex field=_raw "(?(\d{4}-\d{2}-\d{2})[\s]+)"&lt;/P&gt;

&lt;P&gt;expected output&lt;/P&gt;

&lt;P&gt;2018-05-10&lt;/P&gt;

&lt;P&gt;The search you have given me does not save it in the fields until I run the search everytime&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 19:27:27 GMT</pubDate>
    <dc:creator>vrmandadi</dc:creator>
    <dc:date>2020-09-29T19:27:27Z</dc:date>
    <item>
      <title>how to extract month date and year and save in a new field from _time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388153#M113180</link>
      <description>&lt;P&gt;I am trying to do field extraction from the _time only the month,date and year but just not getting it.I know strftime does what i want but I want to save it into a new field&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
vr&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 17:13:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388153#M113180</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2018-05-10T17:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract month date and year and save in a new field from _time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388154#M113181</link>
      <description>&lt;P&gt;@vrmandadi before trying to extract date, month and year from &lt;CODE&gt;_time&lt;/CODE&gt;, have you analysed raw events in your index in verbose mode to see whether you already have default date fields i.e.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;date_mday, date_month, date_year
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can also try the following search &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt;
| table _time date_mday, date_month, date_year
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Only if for some reason you don't see &lt;CODE&gt;date_*&lt;/CODE&gt; fields, you may try the following regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt;
| eval Time=strftime(_time,"%Y-%m-%d")
| rex field="Time" "^(?&amp;lt;year&amp;gt;[^-]+)-(?&amp;lt;month&amp;gt;[^-]+)-(?&amp;lt;day&amp;gt;.+)"
| table _time Time year month day
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The reason why your regex is not working is that &lt;EM&gt;time is in epoch time format and it needs to be converted to String time first. I have converted _time to Time in example above. As stated, this is not best approach as `date&lt;/EM&gt;*` fields might already be present.&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 17:49:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388154#M113181</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-10T17:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract month date and year and save in a new field from _time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388155#M113182</link>
      <description>&lt;P&gt;hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/201110"&gt;@niketn&lt;/a&gt;&lt;/P&gt;

&lt;P&gt;The data does not have  date_mday, date_month, date_year  that is why I am using regex to save it as  a new field called date for &lt;/P&gt;

&lt;P&gt;_time=2018-05-10 09:33:54&lt;/P&gt;

&lt;P&gt;|rex field=_raw "(?(\d{4}-\d{2}-\d{2})[\s]+)"&lt;/P&gt;

&lt;P&gt;expected output&lt;/P&gt;

&lt;P&gt;2018-05-10&lt;/P&gt;

&lt;P&gt;The search you have given me does not save it in the fields until I run the search everytime&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:27:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388155#M113182</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2020-09-29T19:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract month date and year and save in a new field from _time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388156#M113183</link>
      <description>&lt;P&gt;So you need Date in YYYY-mm-dd format, then rex is not required... Just the following should suffice.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt;
 | eval Time=strftime(_time,"%Y-%m-%d")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, since Splunk deals with time series data, and your request is around manipulation of _time field. I would like to understand your use case so that we do not complicate things. &lt;/P&gt;

&lt;P&gt;Why do you need YYYY-mm-dd?&lt;BR /&gt;
Also once you have dates like 2018-05-10, what is it that you need to do next? &lt;BR /&gt;
Or is it only for displaying to users?&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 18:33:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388156#M113183</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-10T18:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract month date and year and save in a new field from _time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388157#M113184</link>
      <description>&lt;P&gt;I just need to have a field extracted named "date" which has YYYY-MM-DD from the _time ,the eval needs to run everytime,but I want to save it as a extracted field.Yep I want to show it in the fields column&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 18:45:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388157#M113184</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2018-05-10T18:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract month date and year and save in a new field from _time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388158#M113185</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/120532"&gt;@vrmandadi&lt;/a&gt; if you need YYYY-mm-dd to be your _time field you can do so in props.conf using &lt;CODE&gt;TIME_FORMAT&lt;/CODE&gt; and &lt;CODE&gt;MAX_TIMESTAMP_LOOKAHEAD&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;For us to assist you with regular expression you will have to provide sample of your raw event with timestamp field. We would be interested in exact string time format in data and any pattern before or after timestamp field.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:30:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388158#M113185</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T19:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract month date and year and save in a new field from _time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388159#M113186</link>
      <description>&lt;P&gt;You would need to setup a calculated field to saved the strftime command output as a saved field. If you're creating the field using Splunk Web UI, follow instruction from below link.&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.1.0/Knowledge/CreatecalculatedfieldswithSplunkWeb"&gt;https://docs.splunk.com/Documentation/Splunk/7.1.0/Knowledge/CreatecalculatedfieldswithSplunkWeb&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;For name give the &lt;CODE&gt;date&lt;/CODE&gt; and for Eval expression use &lt;CODE&gt;strftime(_time,"%Y-%m-%d")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;To save the same thing in configuration files (if deploying through Deployer OR deployment server), add this in props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[yourSourcetypeNameHere]
EVAL-date = strftime(_time,"%Y-%m-%d")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 May 2018 19:54:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388159#M113186</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-05-10T19:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract month date and year and save in a new field from _time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388160#M113187</link>
      <description>&lt;P&gt;Thank you calculated fields has done the trick&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 20:25:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-extract-month-date-and-year-and-save-in-a-new-field-from/m-p/388160#M113187</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2018-05-10T20:25:47Z</dc:date>
    </item>
  </channel>
</rss>

