<?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: variance betweeen _time and date_* fields in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38119#M6992</link>
    <description>&lt;P&gt;You could create a macro to help your user base. I'd call the macro something like &lt;CODE&gt;normalize_datetime&lt;/CODE&gt; and have it calculate/override the existing &lt;CODE&gt;date*&lt;/CODE&gt; fields. This macro could also be used on data that has no &lt;CODE&gt;date*&lt;/CODE&gt; fields, providing an added benefit.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eval date_hour = strftime(_time, "%H") | eval date_mday = strftime(_time, "%d") | eval  date_minute = strftime(_time, "%M") | eval  date_month = strftime(_time, "%m") | eval  date_second = strftime(_time, "%S") | eval  date_wday = strftime(_time, "%a") | eval  date_year = strftime(_time, "%y") | eval  date_zone = "UTC"&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Aug 2013 17:55:52 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2013-08-20T17:55:52Z</dc:date>
    <item>
      <title>variance betweeen _time and date_* fields</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38116#M6989</link>
      <description>&lt;P&gt;I've got a situation where different date elements are providing inconsistent results for the same time data. I suspect this is a result of index time vs. search time processing and timezone differences between the data presented and data indexed. The data contains a date in UTC, which is converted to MDT by Splunk. The date_* data is incorrect when compared to the _time field, though is correct for the raw timestamp data.&lt;/P&gt;

&lt;P&gt;If this activity were consistent amongst all system provided time fields, I could live with it pretty easily, but the fact that the data presented in the &lt;EM&gt;time field differs from the date&lt;/EM&gt;* fields is problematic. Is this a bug or expected behavior?&lt;/P&gt;

&lt;P&gt;Here's info on the search, data returned, props config, and splunk version&lt;/P&gt;

&lt;P&gt;Search modifiers:&lt;BR /&gt;
| eval wd=lower(strftime(&lt;EM&gt;time,"%A")) | table _time, date&lt;/EM&gt;*, wd&lt;/P&gt;

&lt;P&gt;Raw time data:&lt;BR /&gt;
2013-08-16T05:10:05&lt;/P&gt;

&lt;P&gt;Data presented:&lt;BR /&gt;
_time==8/15/13 11:10:05.000 PM&lt;BR /&gt;
wd==thursday&lt;BR /&gt;
date_wday==friday&lt;BR /&gt;
date_mday==16&lt;BR /&gt;
date_hour==5&lt;/P&gt;

&lt;P&gt;props.conf config:&lt;BR /&gt;
[my_sourcetype]&lt;BR /&gt;
KV_MODE = json&lt;BR /&gt;
MAX_TIMESTAMP_LOOKAHEAD = 500&lt;BR /&gt;
NO_BINARY_CHECK = 1&lt;BR /&gt;
SHOULD_LINEMERGE = false&lt;BR /&gt;
TRUNCATE = 100000&lt;BR /&gt;
TIME_FORMAT = %Y-%m-%dT%H:%M:%S&lt;BR /&gt;
TIME_PREFIX = ,\"start\":\"&lt;BR /&gt;
TZ = UTC&lt;BR /&gt;
pulldown_type = 1&lt;/P&gt;

&lt;P&gt;Splunk version:&lt;BR /&gt;
5.0.4, build 172409&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:35:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38116#M6989</guid>
      <dc:creator>kbrady</dc:creator>
      <dc:date>2020-09-28T14:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: variance betweeen _time and date_* fields</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38117#M6990</link>
      <description>&lt;P&gt;This is expected behavior and is described in the manual &lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0.4/Knowledge/Usedefaultfields"&gt;here&lt;/A&gt;. The &lt;CODE&gt;date*&lt;/CODE&gt; fields are a direct parsing of the text timestamp in the input stream. No timezone is applied to them - in any version of Splunk. These fields do not even exist for inputs that do not use text timestamps; for example, none of them will appear in an input that uses Linux epoch time.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;_time&lt;/CODE&gt; is what I call the "normalized" time field. It is considered the true time that the event occurred and always takes timezone into consideration. &lt;STRONG&gt;All&lt;/STRONG&gt; events have a &lt;CODE&gt;_time&lt;/CODE&gt; field in Splunk, even if the input stream has no timestamp at all.&lt;/P&gt;

&lt;P&gt;If you want to do accurate datetime arithmetic, IMO you should &lt;EM&gt;never&lt;/EM&gt; use the &lt;CODE&gt;date*&lt;/CODE&gt; fields. Instead, you can extract the necessary information from &lt;CODE&gt;_time&lt;/CODE&gt;, as you did in your example search. For example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| eval weekDay = strftime(_time,"%a")
| eval HourOfDay = strftime(_time,"%H")
| table _time, weekDay, HourOfDay
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can also use the &lt;CODE&gt;relative_time&lt;/CODE&gt; function to do some cool date arithmetic. For example, this calculates the beginning of the month for each event, and formats the times nicely:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| eval BeginningOfMonth = strftime(relative_time(_time,"@mon"),"%x %X")
| eval EventTime=strftime(_time,"%x %X")
| table EventTime, BeginningOfMonth
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Aug 2013 01:49:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38117#M6990</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-08-17T01:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: variance betweeen _time and date_* fields</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38118#M6991</link>
      <description>&lt;P&gt;Fair enough, at least it's documented. Not a big deal for me to stop using the date_* fields, but some of my user base will have a harder time.&lt;/P&gt;

&lt;P&gt;Thank you for a solid explanation.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2013 17:19:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38118#M6991</guid>
      <dc:creator>kbrady</dc:creator>
      <dc:date>2013-08-19T17:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: variance betweeen _time and date_* fields</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38119#M6992</link>
      <description>&lt;P&gt;You could create a macro to help your user base. I'd call the macro something like &lt;CODE&gt;normalize_datetime&lt;/CODE&gt; and have it calculate/override the existing &lt;CODE&gt;date*&lt;/CODE&gt; fields. This macro could also be used on data that has no &lt;CODE&gt;date*&lt;/CODE&gt; fields, providing an added benefit.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eval date_hour = strftime(_time, "%H") | eval date_mday = strftime(_time, "%d") | eval  date_minute = strftime(_time, "%M") | eval  date_month = strftime(_time, "%m") | eval  date_second = strftime(_time, "%S") | eval  date_wday = strftime(_time, "%a") | eval  date_year = strftime(_time, "%y") | eval  date_zone = "UTC"&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2013 17:55:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38119#M6992</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-08-20T17:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: variance betweeen _time and date_* fields</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38120#M6993</link>
      <description>&lt;P&gt;I think your macro needs to have:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;        eval  date_wday = strftime(_time, "%A")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;for date_wday (capital "A") to work correctly&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2014 22:13:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38120#M6993</guid>
      <dc:creator>halkelley</dc:creator>
      <dc:date>2014-08-22T22:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: variance betweeen _time and date_* fields</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38121#M6994</link>
      <description>&lt;P&gt;Update: you may find that these fields &lt;EM&gt;do&lt;/EM&gt; exist for inputs that do not use text timestamps. So far, I have not figured out how to remove the &lt;CODE&gt;date_*&lt;/CODE&gt; fields from automatic field extraction - and I have looked... I completely understand the comment "some of my user base will have a harder time"&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2015 00:54:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38121#M6994</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2015-06-11T00:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: variance betweeen _time and date_* fields</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38122#M6995</link>
      <description>&lt;P&gt;Yes, "%a" gives the DOW abbreviation, not the full name of the DOW.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2015 00:54:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/variance-betweeen-time-and-date-fields/m-p/38122#M6995</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2015-06-11T00:54:53Z</dc:date>
    </item>
  </channel>
</rss>

