<?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 do I force a timestamp to be recognized as UTC in a query for strptime? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394523#M114583</link>
    <description>&lt;P&gt;I think I've figured this out. I ended up appending to my strings the "-0000" suffix, and then using your suggestion to obtain the epoch_time. &lt;BR /&gt;
My format string simply omits the "T" in between the %F and %T formatting to apply to my case. &lt;/P&gt;</description>
    <pubDate>Fri, 06 Dec 2019 20:19:47 GMT</pubDate>
    <dc:creator>pgoldweic</dc:creator>
    <dc:date>2019-12-06T20:19:47Z</dc:date>
    <item>
      <title>How do I force a timestamp to be recognized as UTC in a query for strptime?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394519#M114579</link>
      <description>&lt;P&gt;I have a datasource that passes the time as a string like the following:  "2018-08-07T17:38:16.352" &lt;/P&gt;

&lt;P&gt;This string is in UTC time.&lt;/P&gt;

&lt;P&gt;How am I able to get this to just recognize properly as being in UTC using strptime?  No matter what I do it either converts to my local timezone or just doesn't convert it at all and throws it out.  I've tried:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval ts=strptime(ts,"%Y-%m-%dT%H:%M:%S")

|eval ts=strptime(ts,"%Y-%m-%dT%H:%M:%S.%3N")

|eval ts=strptime(ts." UTC","%Y-%m-%dT%H:%M:%S.%3N %Z")

|eval ts=strptime(ts." GMT","%Y-%m-%dT%H:%M:%S.%3N %Z")

|eval ts=strptime(ts." +0000","%Y-%m-%dT%H:%M:%S.%3N %z")

|eval ts=strptime(ts." 0000","%Y-%m-%dT%H:%M:%S.%3N %z")

|eval ts=strptime(ts." 00","%Y-%m-%dT%H:%M:%S.%3N %z")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Absolutely none of these work.  How can I just get this to simply convert properly to the epoch value as if this time string were in UTC?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 18:02:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394519#M114579</guid>
      <dc:creator>briancronrath</dc:creator>
      <dc:date>2018-08-07T18:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I force a timestamp to be recognized as UTC in a query for strptime?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394520#M114580</link>
      <description>&lt;P&gt;try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval epoch_time = strptime(st, "%FT%T.%3N%z")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I used this to verify:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 1
| fields - _time
| eval st = "2018-08-07T17:38:16.352"
| eval epoch_time = strptime(st, "%FT%T.%3N%z")
| eval utc_time = relative_time(epoch_time,strftime(epoch_time,"%z")."h")
| convert ctime(utc_time)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Aug 2018 20:23:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394520#M114580</guid>
      <dc:creator>kmaron</dc:creator>
      <dc:date>2018-08-07T20:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I force a timestamp to be recognized as UTC in a query for strptime?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394521#M114581</link>
      <description>&lt;P&gt;Did the solution proposed work for you? I've also been having a similar issue but with a string that &lt;EM&gt;does not&lt;/EM&gt; have the 'T' itself, although it is encoded as UTC nonetheless. I cannot get the proposed solution to work for me.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 18:02:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394521#M114581</guid>
      <dc:creator>pgoldweic</dc:creator>
      <dc:date>2019-12-05T18:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I force a timestamp to be recognized as UTC in a query for strptime?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394522#M114582</link>
      <description>&lt;P&gt;I have an analogous problem although my strings do not include the "T" in between the date and time, although they are UTC though. When I try your solution, I get no value for the epoch_time field. How would you modify the format string to work in my case?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 18:05:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394522#M114582</guid>
      <dc:creator>pgoldweic</dc:creator>
      <dc:date>2019-12-05T18:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I force a timestamp to be recognized as UTC in a query for strptime?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394523#M114583</link>
      <description>&lt;P&gt;I think I've figured this out. I ended up appending to my strings the "-0000" suffix, and then using your suggestion to obtain the epoch_time. &lt;BR /&gt;
My format string simply omits the "T" in between the %F and %T formatting to apply to my case. &lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 20:19:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394523#M114583</guid>
      <dc:creator>pgoldweic</dc:creator>
      <dc:date>2019-12-06T20:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I force a timestamp to be recognized as UTC in a query for strptime?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394524#M114584</link>
      <description>&lt;P&gt;Just repeating what I explained as a comment to the answer below: I ended up appending to my strings the "-0000" suffix, and then using your suggestion to obtain the epoch_time. My format string simply omits the "T" in between the %F and %T formatting to apply to my case. &lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 20:21:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394524#M114584</guid>
      <dc:creator>pgoldweic</dc:creator>
      <dc:date>2019-12-06T20:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I force a timestamp to be recognized as UTC in a query for strptime?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394525#M114585</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval localtime = strftime(_time, "%F %T.%3N")
| eval epoch_time = _time
| eval time_suffix=strftime(epoch_time,"%:::z")
| eval time_suffix_mod=if(substr(time_suffix,1,1)=="+","-".substr(time_suffix,2),"+".substr(time_suffix,2))
| eval unix_time=relative_time(epoch_time,(time_suffix_mod."h"))
| eval unix_time=strftime(unix_time, "%F %T.%3N")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hi, @pgoldweic &lt;BR /&gt;
There were certainly various problems.&lt;BR /&gt;
How about this?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 22:06:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394525#M114585</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-12-06T22:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I force a timestamp to be recognized as UTC in a query for strptime?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394526#M114586</link>
      <description>&lt;P&gt;Thanks for replying, although I had already figured out the solution, as I pointed out in my comments. I'm not quite sure I've followed fully your suggested solution (and it does not seem to apply as well as the one given by kmaron actually, or perhaps because I'm misunderstanding it). In any case, here's what worked for me:&lt;BR /&gt;
| makeresults&lt;BR /&gt;
| eval st = "2018-08-07 17:38:16.352"."-0000"&lt;BR /&gt;
| eval epochTime = strptime(st, "%F %T.%3N%z")&lt;/P&gt;

&lt;P&gt;This ensures that then I can format the epochTime to display in local time as follows: &lt;BR /&gt;
| eval newlyformattedString = strftime(epochTime, ""%F %T.%3N%z")&lt;/P&gt;

&lt;P&gt;and this displays as "2018-08-07 12:38:16.352-0500" , which is exactly what I needed. Hope this makes sense. Thanks again for your reply!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 23:03:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394526#M114586</guid>
      <dc:creator>pgoldweic</dc:creator>
      <dc:date>2019-12-06T23:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I force a timestamp to be recognized as UTC in a query for strptime?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394527#M114587</link>
      <description>&lt;P&gt;I see, Thank you for the detailed explanation.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 23:19:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/394527#M114587</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-12-06T23:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I force a timestamp to be recognized as UTC in a query for strptime?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/629061#M218498</link>
      <description>&lt;P&gt;Note that this statement in this solution is wrong&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval utc_time = relative_time(epoch_time,strftime(epoch_time,"%z")."h")&lt;/LI-CODE&gt;&lt;P&gt;as it will convert offset to a 4 digit TZ offset (in my case +1100) and append h, so will do a relative_time addition of 1100 hours to my time, whereas it should be +11h.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 22:24:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-force-a-timestamp-to-be-recognized-as-UTC-in-a-query/m-p/629061#M218498</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-01-31T22:24:33Z</dc:date>
    </item>
  </channel>
</rss>

