<?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 format date and time in searches in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169742#M48516</link>
    <description>&lt;P&gt;If your logs are parsed properly, each event will also have a _time field - it appears in the left column when you search. This is the time field that I would use, as it takes into account the fact that different logs and servers may have different timezones.&lt;/P&gt;

&lt;P&gt;To use it as you described:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| eval TimeOutput=strftime(_time,"%x %r")
| fields TimeOutput _raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Although most of the time, Splunk will format the time appropriately for you, depending on the statistics. Exactly what did you want to calculate?&lt;BR /&gt;
You can find out more info about strftime by Googling - it is a standard formatting function in many computer languages.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Aug 2015 05:55:30 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2015-08-13T05:55:30Z</dc:date>
    <item>
      <title>how to format date and time in searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169741#M48515</link>
      <description>&lt;P&gt;In my logs that is pulled into Splunk the time is recorded as datetime="2015-08-13 01:43:38" . So when I do a search and go to the statistics tab, the date and time is displayed with the year first, then the month and the date and the time. How can I format the field so that it will be in the following format&lt;/P&gt;

&lt;P&gt;MM-DD-YYYY 00:00 AM or PM (08-13-2015 01:43 AM)&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 02:22:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169741#M48515</guid>
      <dc:creator>samble</dc:creator>
      <dc:date>2015-08-13T02:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to format date and time in searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169742#M48516</link>
      <description>&lt;P&gt;If your logs are parsed properly, each event will also have a _time field - it appears in the left column when you search. This is the time field that I would use, as it takes into account the fact that different logs and servers may have different timezones.&lt;/P&gt;

&lt;P&gt;To use it as you described:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| eval TimeOutput=strftime(_time,"%x %r")
| fields TimeOutput _raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Although most of the time, Splunk will format the time appropriately for you, depending on the statistics. Exactly what did you want to calculate?&lt;BR /&gt;
You can find out more info about strftime by Googling - it is a standard formatting function in many computer languages.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 05:55:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169742#M48516</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2015-08-13T05:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to format date and time in searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169743#M48517</link>
      <description>&lt;P&gt;use&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| convert timeformat="%m-%d-%Y %l:%M %p" ctime(_time) AS c_time | table _time, c_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval strf_time =strftime(_time, "%m-%d-%Y %l:%M %p")  | table _time, strf_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This results in &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  2015-08-13 06:33:17   08-13-2015 6:33 AM 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are no leading zeros on the hour. See also &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Convert" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Convert&lt;/A&gt; and &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.4/SearchReference/CommonEvalFunctions#Date_and_Time_functions" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.4/SearchReference/CommonEvalFunctions#Date_and_Time_functions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 06:59:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169743#M48517</guid>
      <dc:creator>FritzWittwer_ol</dc:creator>
      <dc:date>2020-09-29T06:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to format date and time in searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169744#M48518</link>
      <description>&lt;P&gt;I do not see _time field as a field that is extracted in the left, but it does use the _time field when displaying the data in the statistics tab. I'm trying to display the temperature in the data closets for a 24 hour period in a dashboard using the time chart function. When I try the above it does display the time correctly ( would be nice if I could display time as 00:00 AM or PM instead and avoid the seconds)  but the columns for the cabinets is missing. Now I end up with only 3 columns timeoutput, _raw and time&lt;/P&gt;

&lt;P&gt;Below is my original search&lt;/P&gt;

&lt;P&gt;key=Temp | timechart span=30m latest(value) by host limit=0&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 11:06:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169744#M48518</guid>
      <dc:creator>samble</dc:creator>
      <dc:date>2015-08-13T11:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to format date and time in searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169745#M48519</link>
      <description>&lt;P&gt;Do it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;key=Temp | timechart span=30m latest(value) by host limit=0 | fieldformat _time = strftime(_time,"%x %r")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Aug 2015 12:58:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169745#M48519</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-13T12:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to format date and time in searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169746#M48520</link>
      <description>&lt;P&gt;Now it displays all the columns I want, but the time is not displayed correctly, it just has a bunch of characters under the _time column. Below is an example.&lt;/P&gt;

&lt;P&gt;_time&lt;BR /&gt;
0NaN-NaN-NaN NaN:NaN:NaN&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 13:02:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169746#M48520</guid>
      <dc:creator>samble</dc:creator>
      <dc:date>2015-08-13T13:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to format date and time in searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169747#M48521</link>
      <description>&lt;P&gt;Are you sure you copied it exactly as the answer?  I just re-tested it and it works fine.  How are your events created (perhaps something is not creating the &lt;CODE&gt;_time&lt;/CODE&gt; field correctly because the error is from &lt;CODE&gt;strftime&lt;/CODE&gt; saying that it is not finding a number to use N=Not, a=a, N=Number -&amp;gt; NaN -&amp;gt; Not-a-Number.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 13:21:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169747#M48521</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-13T13:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to format date and time in searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169748#M48522</link>
      <description>&lt;P&gt;Thank you for taking the time to answer this question. I copied the line above as is in my search window and that is what I got. Below is how the time is displayed in the logs.&lt;/P&gt;

&lt;P&gt;server host="NOC 06thFL E" address="xxx.xx.xxx.xx" name="WatchDog 15" product-version="1.5.1" mac-address="00:04:A3:C9:BD:CF" datetime="2015-08-13 13:25:58"&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 13:39:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169748#M48522</guid>
      <dc:creator>samble</dc:creator>
      <dc:date>2015-08-13T13:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to format date and time in searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169749#M48523</link>
      <description>&lt;P&gt;The field _time (or any field starting with underscore) is special/internal fields generated by Splunk and will not be visible on the Field sidebar. Also, since this is a special field, the fieldformat does't really changes the format of _time, so what you need to do is to create a new regular field and use that. e.g.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;key=Temp | timechart span=30m latest(value) by host limit=0 | eval Timestamp=strftime(_time,"%x %r") | fields - _time | table Timestamp *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Aug 2015 15:20:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169749#M48523</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-08-13T15:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to format date and time in searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169750#M48524</link>
      <description>&lt;P&gt;That did the trick, now I have the table in the way it should be. Thanks again.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 15:31:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-format-date-and-time-in-searches/m-p/169750#M48524</guid>
      <dc:creator>samble</dc:creator>
      <dc:date>2015-08-13T15:31:59Z</dc:date>
    </item>
  </channel>
</rss>

