<?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: Why is date_hour inconsistent with %H? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269726#M190005</link>
    <description>&lt;P&gt;To close the loop.  After reviewing @lgnuin's comment about the doco being wrong and discovering the correct note in the same doco page, the above example can be explained - as kind of &lt;EM&gt;expected&lt;/EM&gt; behavior.  Here, syslog is not logging year, so Splunk discarded "Mar 29 17:54:11" and supplied indexer timestamp .  Per the correct part of the doco: "If you have ... changed the value of the time/date at indexing or input time (for example, by setting the timestamp to be the time at index or input time), these fields will not represent that."&lt;/P&gt;

&lt;P&gt;In this sense, it is not a bug.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Mar 2016 22:45:35 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2016-03-29T22:45:35Z</dc:date>
    <item>
      <title>Why is date_hour inconsistent with %H?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269720#M189999</link>
      <description>&lt;P&gt;According to doco: "The date_hour field ... is extracted from the event's timestamp (the value in _time)."  Consider this test:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=*
| eval hour=strftime(_time,"%H")
| eval shift=date_hour-hour
| stats count by shift index date_zone
| stats values(eval(index."-".count)) as sourcetype sum(count) as count by shift date_zone
| sort by -shift
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output is all over the map:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;shift   date_zone   sourcetype  count
17      local   main-3550674
                   r-7006
                   sample-16093    3573773
16      local    r-1572       1572
0       0        main-1158239   1158239
-7      local   main-3817593
                   r-18887
                   sample-41819    3878299
-8      local    main-1626
                   r-2839         4465
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I examine raw data closely, it seems that strftime(_time,"%H") reports the hour of day correctly.&lt;/P&gt;

&lt;P&gt;Similar inconsistence exists in date_mday vs "%d".&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 20:51:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269720#M189999</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2016-03-29T20:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Why is date_hour inconsistent with %H?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269721#M190000</link>
      <description>&lt;P&gt;The one case where I know date_* fields are all a bit wrong, is when _time is being extracted from an epochtime value.   ie when &lt;CODE&gt;_time&lt;/CODE&gt; is calculated from something in the raw event text that is itself a number of seconds since 1970. &lt;/P&gt;

&lt;P&gt;date_hour and date_minute and all its friends,  are technically not always extracted.  In cases where the timestamp extraction can't find a reliable &lt;EM&gt;timezone&lt;/EM&gt;,  Splunk isn't supposed to create any of these fields.  That by the way can be a surprise for people who have come to expect they are always there. &lt;/P&gt;

&lt;P&gt;But in the case of &lt;CODE&gt;_time&lt;/CODE&gt; is extracted from an epochtime value in the events,  even though in such a case the timestamp-extraction code really has no valid timezone listed there,  it has always as far as I know had a bug in it where it will erroneously assume the data is in GMT, and go on to create date_* fields as though the data were unequivocally in GMT.    &lt;/P&gt;

&lt;P&gt;The only recourse that I know of,  is to just stop trusting date_* completely when you're using one of these data sets. &lt;BR /&gt;
Or to hardcode an offset into your search that represents your offset from GMT, (and then change it twice a year for DST!).    I recommend not trusting it, and just creating your own little fields in props.conf. &lt;/P&gt;

&lt;P&gt;EVAL-hour_of_day=strftime(_time,"%H")&lt;BR /&gt;
EVAL-day_of_week=strftime(_time,"%a")&lt;/P&gt;

&lt;P&gt;It's been this way for years, I've filed it several times as a bug,  I've even had conversations with engineering (years ago now) about why it's a tremendous pain for them to fix.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:16:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269721#M190000</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2020-09-29T09:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Why is date_hour inconsistent with %H?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269722#M190001</link>
      <description>&lt;P&gt;Yes, what @sideview said: "stop trusting &lt;CODE&gt;date_*&lt;/CODE&gt; completely" - although I would go even farther and say "don't use &lt;CODE&gt;date_*&lt;/CODE&gt;".&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;_time&lt;/CODE&gt; is "normalized" - by that I mean: it is parsed by Splunk, using any timezone and props.conf information available; it is stored in the index in UTC; it is displayed to you based on your user timezone setting in the GUI. If you extract the hour (&lt;CODE&gt;%H&lt;/CODE&gt;) from &lt;CODE&gt;_time&lt;/CODE&gt;, it will always be "right" and it always exists.&lt;/P&gt;

&lt;P&gt;I would really like to have a way to suppress the date fields altogether, so that users can't see them and use them without understanding the consequences.&lt;/P&gt;

&lt;P&gt;From this page in the Splunk Docs:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.3/Knowledge/UseDefaultFields"&gt;http://docs.splunk.com/Documentation/Splunk/6.3.3/Knowledge/UseDefaultFields&lt;/A&gt;&lt;BR /&gt;
"The datetime values are the literal values parsed from the event when it is indexed, regardless of its timezone."&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 21:36:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269722#M190001</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2016-03-29T21:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why is date_hour inconsistent with %H?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269723#M190002</link>
      <description>&lt;P&gt;Where did you find that statement in the documentation? I couldn't find it - and I think it is wrong...&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 21:59:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269723#M190002</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2016-03-29T21:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Why is date_hour inconsistent with %H?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269724#M190003</link>
      <description>&lt;P&gt;I have this example, where _time is not from an epoch time in the source event, a syslog entry&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Mar 29 17:54:11 amiohdrmp1 snmpd[14773]: Connection from UDP: [127.0.0.1]:46920 &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;In this particular case, syslog uses EDT without printing zone info.  Splunk correctly dates this event at 3/29/16 9:54:11.000 PM, i.e., 21:54:11.  As a result, %H correctly gives 21.  However, date_hour is 17, the split output from source text!&lt;/P&gt;

&lt;P&gt;Whereas this case looks like a fixable bug, the designer may have other use cases in mind.  You have sufficiently scared me, so I'll just accept "in date_* no trust" as answer:-)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 22:14:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269724#M190003</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2016-03-29T22:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: Why is date_hour inconsistent with %H?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269725#M190004</link>
      <description>&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.3/Knowledge/UseDefaultFields" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/6.3.3/Knowledge/UseDefaultFields&lt;/A&gt; - scroll down to "Default datetime fields".  The statement surely &lt;STRONG&gt;is&lt;/STRONG&gt; wrong in the sample that I just examined.&lt;/P&gt;

&lt;P&gt;Interestingly, closer to the top of the doco, there is a &lt;STRONG&gt;correct&lt;/STRONG&gt; note:&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;: Only events that have timestamp information in them as generated by their respective systems will have date_* fields. If an event has a date_* field, it represents the value of time/date directly from the event itself. If you have specified any timezone conversions or changed the value of the time/date at indexing or input time (for example, by setting the timestamp to be the time at index or input time), these fields will not represent that.&lt;/P&gt;

&lt;HR /&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:16:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269725#M190004</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2020-09-29T09:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Why is date_hour inconsistent with %H?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269726#M190005</link>
      <description>&lt;P&gt;To close the loop.  After reviewing @lgnuin's comment about the doco being wrong and discovering the correct note in the same doco page, the above example can be explained - as kind of &lt;EM&gt;expected&lt;/EM&gt; behavior.  Here, syslog is not logging year, so Splunk discarded "Mar 29 17:54:11" and supplied indexer timestamp .  Per the correct part of the doco: "If you have ... changed the value of the time/date at indexing or input time (for example, by setting the timestamp to be the time at index or input time), these fields will not represent that."&lt;/P&gt;

&lt;P&gt;In this sense, it is not a bug.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 22:45:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269726#M190005</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2016-03-29T22:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Why is date_hour inconsistent with %H?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269727#M190006</link>
      <description>&lt;P&gt;Actually, Splunk does &lt;EM&gt;not&lt;/EM&gt; discard "Mar 29 17:54:11"&lt;/P&gt;

&lt;P&gt;If the event arrived to be indexed &lt;EM&gt;before&lt;/EM&gt; Mar 29, &lt;STRONG&gt;2016&lt;/STRONG&gt;, Splunk would assume the year to be &lt;STRONG&gt;2015&lt;/STRONG&gt;. Otherwise, Splunk would assume the current year (2016). &lt;BR /&gt;
(An easier-to-understand example: if an event showed up today (30-Mar-2016) with a timestamp of "Aug 9 17:54:11", Splunk would assume 2015. For a timestamp of "Feb 2 17:54:11", it would assume 2016.)&lt;/P&gt;

&lt;P&gt;Many, many timestamps have this form, although syslog is the most common. If Splunk wasn't able to deal with this, a lot of inputs would be broken.&lt;/P&gt;

&lt;P&gt;Why did Splunk figure it was EDT? Check out this docs page, in the section &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.2/data/Applytimezoneoffsetstotimestamps"&gt;How Splunk applies time zones&lt;/A&gt; My guess is that the forwarder supplied the timezone of the underlying OS.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2016 20:39:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-date-hour-inconsistent-with-H/m-p/269727#M190006</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2016-03-30T20:39:06Z</dc:date>
    </item>
  </channel>
</rss>

