<?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: Changing the time format form a log file using eval. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114090#M30123</link>
    <description>&lt;P&gt;The &lt;CODE&gt;stats&lt;/CODE&gt; command is displaying &lt;CODE&gt;logintime&lt;/CODE&gt;, which is epoch time (the output of strptime()).  To see the desired time string, put &lt;CODE&gt;desired_time&lt;/CODE&gt; in the &lt;CODE&gt;stats&lt;/CODE&gt; command.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Nov 2014 13:16:26 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2014-11-07T13:16:26Z</dc:date>
    <item>
      <title>Changing the time format form a log file using eval.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114086#M30119</link>
      <description>&lt;P&gt;I am running a report that outputs a date and time format form one of my logs, and sending it in email to a customer.  they cannot create a pivot table off the time as excel does not recognize the format.  I am attemtping to change the date/time stamp field to a new value (logintime) with the new date format.  &lt;/P&gt;

&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;

&lt;P&gt;index=indexname Field=Value | eval logintime = strptime(timefield, "%a %b %d:%H:%M:%S %Z %Y") | eval desired_time=strftime(logintime, "%d/%m/%Y %I:%M:%S %p") | fields - logintime | stats count by UserData_LastName logintime&lt;/P&gt;

&lt;P&gt;Current time format=Thu Nov 06 11:03:18 EST 2014&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:08:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114086#M30119</guid>
      <dc:creator>pete_charlton</dc:creator>
      <dc:date>2020-09-28T18:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the time format form a log file using eval.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114087#M30120</link>
      <description>&lt;P&gt;The &lt;CODE&gt;strptime&lt;/CODE&gt; format string has an extra colon in it.  Try '%a %b %d %H:%M:%S %Z %Y'.  Also, the &lt;CODE&gt;stats&lt;/CODE&gt; command refers to &lt;CODE&gt;logintime&lt;/CODE&gt; which was dropped by the preceding &lt;CODE&gt;fields&lt;/CODE&gt; command.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Nov 2014 12:56:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114087#M30120</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2014-11-07T12:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the time format form a log file using eval.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114088#M30121</link>
      <description>&lt;P&gt;Thanks Rich,&lt;/P&gt;

&lt;P&gt;My output seems to show up in epoch time.   &lt;/P&gt;

&lt;P&gt;Time format after execution1415328453.000000&lt;/P&gt;

&lt;P&gt;eval logintime = strptime(responseIssueInstant, "%a %b %d %H:%M:%S %Z %Y") | eval desired_time=strftime(logintime, "%d/%m/%Y %I:%M:%S %p") | stats count by UserData_LastName logintime&lt;/P&gt;

&lt;P&gt;pete_charlton gravatar image&lt;BR /&gt;&lt;BR /&gt;
Answer by pete_charlton&lt;BR /&gt;
2 secs ago&lt;BR /&gt;
Add comment ·  Accept&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:08:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114088#M30121</guid>
      <dc:creator>pete_charlton</dc:creator>
      <dc:date>2020-09-28T18:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the time format form a log file using eval.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114089#M30122</link>
      <description>&lt;P&gt;Which part of your search isn't working?  Creating a new time field?  Or just reporting it?  &lt;/P&gt;

&lt;P&gt;The first thing I would do would be to change the &lt;CODE&gt;stats&lt;/CODE&gt; portion of your search.  You are getting rid of the &lt;STRONG&gt;logintime&lt;/STRONG&gt; field with the &lt;CODE&gt;fields&lt;/CODE&gt; command, so when you reference it later in your &lt;CODE&gt;stats&lt;/CODE&gt; command, there won't be anything there.&lt;/P&gt;

&lt;P&gt;Is &lt;STRONG&gt;timefield&lt;/STRONG&gt; in your first &lt;CODE&gt;eval&lt;/CODE&gt; is the same thing as the event's time (i.e. _time)?  If so, you could do something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=indexname Field=Value | eval desired_time=strftime(_time, "%d/%m/%Y %I:%M:%S %p") | stats count by UserData_LastName desired_time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Nov 2014 13:12:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114089#M30122</guid>
      <dc:creator>wpreston</dc:creator>
      <dc:date>2014-11-07T13:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the time format form a log file using eval.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114090#M30123</link>
      <description>&lt;P&gt;The &lt;CODE&gt;stats&lt;/CODE&gt; command is displaying &lt;CODE&gt;logintime&lt;/CODE&gt;, which is epoch time (the output of strptime()).  To see the desired time string, put &lt;CODE&gt;desired_time&lt;/CODE&gt; in the &lt;CODE&gt;stats&lt;/CODE&gt; command.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Nov 2014 13:16:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114090#M30123</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2014-11-07T13:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the time format form a log file using eval.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114091#M30124</link>
      <description>&lt;P&gt;I think all you need to do now is change your stats command to use desired_time instead of logintime.  Your are eval'ing logintime to epoch format, then from it creating a new field in human readable format called desired_time, but you're still referencing the epoch time field in stats.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:06:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114091#M30124</guid>
      <dc:creator>wpreston</dc:creator>
      <dc:date>2020-09-28T18:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the time format form a log file using eval.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114092#M30125</link>
      <description>&lt;P&gt;Thank you both!  that did the trick&lt;/P&gt;</description>
      <pubDate>Fri, 07 Nov 2014 13:20:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Changing-the-time-format-form-a-log-file-using-eval/m-p/114092#M30125</guid>
      <dc:creator>pete_charlton</dc:creator>
      <dc:date>2014-11-07T13:20:26Z</dc:date>
    </item>
  </channel>
</rss>

