<?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 date time format from EST to UTC? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294898#M88989</link>
    <description>&lt;P&gt;&lt;CODE&gt;strptime&lt;/CODE&gt; automatically converts the time string from the specified offset to the server's local time.  The offset from that to UTC will be constant.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Feb 2017 14:09:16 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2017-02-13T14:09:16Z</dc:date>
    <item>
      <title>How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294892#M88983</link>
      <description>&lt;P&gt;I have a date field in the format "2017-02-10T10:24:58.290-05:00", which means 10:24:58 in EST timezone. How do I convert it to straight UTC time "2017-02-10T15:24:58.290"? The data is already indexed so I can only do it at search time.  There were some similar questions but I could not find a good way to do it. Do I miss something obvious here?&lt;/P&gt;

&lt;P&gt;Thanks! &lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 20:25:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294892#M88983</guid>
      <dc:creator>Dev999</dc:creator>
      <dc:date>2017-02-10T20:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294893#M88984</link>
      <description>&lt;P&gt;Just a toss in the dark here, could you try:&lt;/P&gt;

&lt;P&gt;| eval time=strftime(_time, "%H/%M/%S")&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 20:45:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294893#M88984</guid>
      <dc:creator>ECovell</dc:creator>
      <dc:date>2017-02-10T20:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294894#M88985</link>
      <description>&lt;P&gt;This should get you started.  It's not very portable, but gets the job done.  Note that the "+5h" argument to &lt;CODE&gt;relative_time&lt;/CODE&gt; needs to be the offset to UTC from the Splunk server's time zone, not the data's time zone.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval utc=strftime(relative_time(strptime(est,"%Y-%m-%dT%H:%M:%S.%3N%z"),"+5h"),"%Y-%m-%dT%H:%M:%S.%3NZ")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Feb 2017 20:49:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294894#M88985</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-02-10T20:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294895#M88986</link>
      <description>&lt;P&gt;The value is from the data that is already indexed, and can be from different time zones ("-5:00" can be different values). I need to extract the field and make it a UTC time. I can make it work with a bunch of eval statements but seems too convoluted for such a simple common job. &lt;BR /&gt;
Thanks for your response.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 21:54:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294895#M88986</guid>
      <dc:creator>Dev999</dc:creator>
      <dc:date>2017-02-10T21:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294896#M88987</link>
      <description>&lt;P&gt;Here is what I meant by convoluted way:) Gotta have a better solution...&lt;/P&gt;

&lt;P&gt;| eval _tt1 = strptime(st, "%Y-%m-%dT%H:%M:%S.%3Q%:z") | eval _tt2 = strftime(_tt1, "%:z") | rex field=_tt2 "(?[+-])(?[^:]&lt;EM&gt;):(?[\d]&lt;/EM&gt;)" | convert num(hh) as hh | convert num(mm) as  mm | eval sec = (hh*60*60 + mm*60) | eval offset=if(pm=="-", sec*(-1), sec) | eval _tt3 = _tt1 - offset | eval utc_time = strftime(_tt3, "%Y-%m-%d %H:%M:%S.%3Q")&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:50:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294896#M88987</guid>
      <dc:creator>Dev999</dc:creator>
      <dc:date>2020-09-29T12:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294897#M88988</link>
      <description>&lt;OL&gt;
&lt;LI&gt;For data already indexed, you can use Eval's &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions#Date_and_Time_functions"&gt;strptime&lt;/A&gt; OR  the &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Convert"&gt;convert&lt;/A&gt; command to switch this to epoch. Once in epoch you can let Splunk represent it in the relative local timezone of the viewer OR always in EPOCH easily using Eval's &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions#Date_and_Time_functions"&gt;strptime&lt;/A&gt; OR  the &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Convert"&gt;convert&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;If this is supposed to be the _time field, then make sure to update the sourcetype to properly extract this value, regardless of timezone, going forwarder. You can use the same Eval's &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions#Date_and_Time_functions"&gt;strptime&lt;/A&gt; &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables"&gt;syntax&lt;/A&gt; in the sourcetype definition&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Here's an example where I create a new field using your example set to &lt;CODE&gt;st&lt;/CODE&gt;. Then I use the strptime syntax (which dynamically pulls the timezone). The value is then as epoch (which I believe is UTC/GMT by definition). Then display the utctime by using the epoch's timezone as a relative shifter.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="screenshot"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/2475i50CFDA7E7C01CE60/image-size/large?v=v2&amp;amp;px=999" role="button" title="screenshot" alt="screenshot" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 13:25:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294897#M88988</guid>
      <dc:creator>sloshburch</dc:creator>
      <dc:date>2017-02-13T13:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294898#M88989</link>
      <description>&lt;P&gt;&lt;CODE&gt;strptime&lt;/CODE&gt; automatically converts the time string from the specified offset to the server's local time.  The offset from that to UTC will be constant.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 14:09:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294898#M88989</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-02-13T14:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294899#M88990</link>
      <description>&lt;P&gt;Thanks Burch.  But here is exactly where my problem is. The utctime is still 10:24, not 15:24 as I would expect. &lt;BR /&gt;
But I think that's how the date time is supposed to work, instead of changing the hours ,it uses a timezone field (%Z). &lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 14:45:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294899#M88990</guid>
      <dc:creator>Dev999</dc:creator>
      <dc:date>2017-02-13T14:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294900#M88991</link>
      <description>&lt;P&gt;The &lt;CODE&gt;utctime&lt;/CODE&gt; is the epoch time (which by definition, is relative to the epoch). I think the challenge here is that when I render the time back (using the &lt;CODE&gt;convert&lt;/CODE&gt; command), it displays as the local time zone.&lt;/P&gt;

&lt;P&gt;Here's how we can take the timezone as a relative adjuster to the time and shift what renders to UTC: &lt;/P&gt;

&lt;P&gt;| makeresults 1&lt;BR /&gt;
 | fields - _time&lt;BR /&gt;
 | eval st = "2017-02-10T10:24:58.290-05:00"&lt;BR /&gt;
 | eval epoch_time = strptime( st, "%FT%T.%3N%:z" ), utc_time = relative_time( epoch_time , strftime( epoch_time , "%z" ) . "h" )&lt;BR /&gt;
 | convert ctime(utc_time)&lt;/P&gt;

&lt;P&gt;I'll update the image in the first post to show this.&lt;/P&gt;

&lt;P&gt;Alternatively, are you able to convert the other data (that is already in UTC) into the local time?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:47:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294900#M88991</guid>
      <dc:creator>sloshburch</dc:creator>
      <dc:date>2020-09-29T12:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294901#M88992</link>
      <description>&lt;P&gt;It would not be able to handle Indian time, and not sure why it's 14:24, not 15:24?&lt;/P&gt;

&lt;P&gt;It turns out strptime would convert to system locale:&lt;BR /&gt;
&lt;CODE&gt;|makeresults 1 | eval st = "2017-02-10T10:24:58.290+05:30" &lt;BR /&gt;
| eval tt1 = strptime(st, "%Y-%m-%dT%H:%M:%S.%3Q%:z") &lt;BR /&gt;
| eval tt2 = strftime(tt1, "%Y-%m-%dT%H:%M:%S.%3Q%:z") &lt;BR /&gt;
| eval offset=strftime(tt1, "%:z") &lt;BR /&gt;
| table st, tt2, offset&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;The result is surprising:  offset: -5:00. tt2: "2017-02-09T23:54:58.290-05:00". So if my splunk server was set to GMT then it would be all set.&lt;/P&gt;

&lt;P&gt;Creating a python command is much easier and does not require server settings change. &lt;/P&gt;

&lt;P&gt;It would be nice if Splunk can provide a standard command like astimezone(epoch_time, zone_name)  similar to that in python dateutil. It would only need a few lines of code.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:53:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294901#M88992</guid>
      <dc:creator>Dev999</dc:creator>
      <dc:date>2020-09-29T12:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294902#M88993</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Similar to many of the suggestions above, I'd go for something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| fields - _time
| eval st = "2017-02-10T10:24:58.290-05:00"
| rex field="st" "(?&amp;lt;offset_h&amp;gt;[-+]\d{2}):(?&amp;lt;offset_m&amp;gt;\d{2})$"
| eval offset=((tonumber(offset_h)*60*60)+(tonumber(offset_m)*60))*-1
| eval st_epoch = strptime(st,"%Y-%m-%dT%H:%M:%S.%3f")
| eval st_local = strftime(strptime(st,"%Y-%m-%dT%H:%M:%S.%3f%:z"),"%Y-%m-%dT%H:%M:%S.%3f%:z")
| eval st_utc = strftime(st_epoch+offset,"%Y-%m-%dT%H:%M:%S.%3f")."-00:00"
| eval st_utc_epoch = strptime(st_utc,"%Y-%m-%dT%H:%M:%S.%3f%:z")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will give you a variety of options to play with. Depending on what your requirement is, you could either pick the &lt;CODE&gt;st_utc&lt;/CODE&gt; or the &lt;CODE&gt;st_local&lt;/CODE&gt; field.&lt;/P&gt;

&lt;P&gt;I'm currently in a (+07:00) timezone, so these are my results:&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/2477i110F7C4313E41D80/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>Thu, 16 Feb 2017 01:16:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294902#M88993</guid>
      <dc:creator>gvmorley</dc:creator>
      <dc:date>2017-02-16T01:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294903#M88994</link>
      <description>&lt;P&gt;What makes you say it won't be able to handle Indian time? I thought the 1 hour shift has to do with daylight savings time?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 13:11:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294903#M88994</guid>
      <dc:creator>sloshburch</dc:creator>
      <dc:date>2017-02-16T13:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date time format from EST to UTC?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294904#M88995</link>
      <description>&lt;P&gt;This is essentially the same as my "convoluted" solution.  In my opinion, it has general usage and should not take that much code to do such a trivial work. strptime does get the correct epoch time (UTC), just need an elegant way to convert it in any given time zone.   Python added astimezone() method in dateutil (not datetime), so it has demand. &lt;/P&gt;

&lt;P&gt;Thanks a lot for your time!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 13:54:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-date-time-format-from-EST-to-UTC/m-p/294904#M88995</guid>
      <dc:creator>Dev999</dc:creator>
      <dc:date>2017-02-16T13:54:14Z</dc:date>
    </item>
  </channel>
</rss>

