<?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 convert microseconds to date time unit in Splunk? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278696#M84181</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;* | rex "Timestamp:\s(?&amp;lt;request_time&amp;gt;\d+)\s(?&amp;lt;response_time&amp;gt;\d+)" | eval stripped_time=strftime(request_time/1000,"%Y-%m-%d %T %z")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;EDIT: Based on other comments:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; * | rex "Timestamp:\s(?&amp;lt;request_time&amp;gt;\d+)\s(?&amp;lt;response_time&amp;gt;\d+)" | eval _time=request_time/1000 | timechart ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 13 Dec 2016 16:24:26 GMT</pubDate>
    <dc:creator>twinspop</dc:creator>
    <dc:date>2016-12-13T16:24:26Z</dc:date>
    <item>
      <title>How to convert microseconds to date time unit in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278694#M84179</link>
      <description>&lt;P&gt;I have a log event like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Timestamp: 1477292160453180 537
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The number &lt;CODE&gt;1477292160453180&lt;/CODE&gt; is the number of microseconds since the Epoch: 1970-01-01 00:00:00 +0000 (UTC). Which in this case comes out to January 1, 2016.&lt;/P&gt;

&lt;P&gt;How do I perform this conversion from microseconds to a time unit in Splunk? Here's my current search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | rex field=_raw "Timestamp:\s(?&amp;lt;request_time&amp;gt;\d+)\s(?&amp;lt;response_time&amp;gt;\d+)" | eval stripped_time=strptime(request_time,"%s%3N")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But that's giving me a table of weirdly formatted &lt;CODE&gt;stripped_time&lt;/CODE&gt; values.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 16:14:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278694#M84179</guid>
      <dc:creator>johnbernal553</dc:creator>
      <dc:date>2016-12-13T16:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert microseconds to date time unit in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278695#M84180</link>
      <description>&lt;P&gt;Hi johnbernal553,&lt;BR /&gt;
what do you want as outputs: an epoch time or an human readable format?&lt;BR /&gt;
with strptime you have an epochtime, to have an human readable time you must use strpftime.&lt;BR /&gt;
Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 16:22:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278695#M84180</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2016-12-13T16:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert microseconds to date time unit in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278696#M84181</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;* | rex "Timestamp:\s(?&amp;lt;request_time&amp;gt;\d+)\s(?&amp;lt;response_time&amp;gt;\d+)" | eval stripped_time=strftime(request_time/1000,"%Y-%m-%d %T %z")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;EDIT: Based on other comments:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; * | rex "Timestamp:\s(?&amp;lt;request_time&amp;gt;\d+)\s(?&amp;lt;response_time&amp;gt;\d+)" | eval _time=request_time/1000 | timechart ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Dec 2016 16:24:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278696#M84181</guid>
      <dc:creator>twinspop</dc:creator>
      <dc:date>2016-12-13T16:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert microseconds to date time unit in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278697#M84182</link>
      <description>&lt;P&gt;I want to convert the milliseconds to a human readable date so that  I can do &lt;CODE&gt;... | eval _time=stripped_time | timechart...&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 16:25:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278697#M84182</guid>
      <dc:creator>johnbernal553</dc:creator>
      <dc:date>2016-12-13T16:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert microseconds to date time unit in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278698#M84183</link>
      <description>&lt;P&gt;_time is not human readable, it's just that Splunk will make it so when you use it in a table. What you want is the _time field in epoch. &lt;CODE&gt;... | eval _time=request_time/1000 | timechart ...&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:04:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278698#M84183</guid>
      <dc:creator>twinspop</dc:creator>
      <dc:date>2020-09-29T12:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert microseconds to date time unit in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278699#M84184</link>
      <description>&lt;P&gt;beat me to it &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 16:33:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278699#M84184</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2016-12-13T16:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert microseconds to date time unit in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278700#M84185</link>
      <description>&lt;P&gt;Are you sure 1477292160453180 is milliseconds and not microseconds?&lt;BR /&gt;
In any case, try the following instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw "Timestamp:\s(?&amp;lt;request_time_secs&amp;gt;\d+)(?&amp;lt;request_time_microsecs&amp;gt;\d{6})\s(?&amp;lt;response_time&amp;gt;\d+)" 
| eval request_time = toNumber(request_time_secs + "." + request_time_microsecs)
| fieldformat request_time = strftime(request_time, "%Y-%m-%d %H:%M:%S.%6N")
| eval _time = request_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | fields - count
| eval request_time = 1477292160453180
| rex field=request_time "(?&amp;lt;request_time_secs&amp;gt;\d+)(?&amp;lt;request_time_microsecs&amp;gt;\d{6})"
| eval request_time = toNumber(request_time_secs + "." + request_time_microsecs)
| fieldformat request_time = strftime(request_time, "%Y-%m-%d %H:%M:%S.%6N")
| eval _time = request_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output (see picture below):&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/2235i208B766C69181CFE/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 16:37:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278700#M84185</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-12-13T16:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert microseconds to date time unit in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278701#M84186</link>
      <description>&lt;P&gt;But this isn't formatting the x-axis properly. Basically I want to have the days as a continuous timeline on the x-axis and the response times on the y-axis, which is the &lt;CODE&gt;537&lt;/CODE&gt; in this case. So that I can see the response times of my application in the past X days.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 16:38:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278701#M84186</guid>
      <dc:creator>johnbernal553</dc:creator>
      <dc:date>2016-12-13T16:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert microseconds to date time unit in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278702#M84187</link>
      <description>&lt;P&gt;This worked perfectly. And yes it was microseconds and not milliseconds. Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 16:58:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-microseconds-to-date-time-unit-in-Splunk/m-p/278702#M84187</guid>
      <dc:creator>johnbernal553</dc:creator>
      <dc:date>2016-12-13T16:58:32Z</dc:date>
    </item>
  </channel>
</rss>

