<?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 How to check if a time field is between two hour values? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-check-if-a-time-field-is-between-two-hour-values/m-p/480017#M82315</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have a situation where I need to check if a time field, 'report_date' in format "%Y-%m-%d %H:%M:%S" happened between 7 AM and 4 PM of that same day. I cant figure out how to do that comparison. I dont know how to get the hour value from my report_date field.&lt;/P&gt;

&lt;P&gt;I'm trying to do that so I can make a filter to see how many reports were made in a specific period of the day so I can tell which shift recieved the report (the recieving time is not the same as the event time in splunk in that particular scenario), and I need to filter by shift.&lt;/P&gt;

&lt;P&gt;So far what I did:&lt;BR /&gt;
index=raw_maximo INCIDENTE=I* GR_RESP="OPERACAO"&lt;BR /&gt;
| eval shift1=strptime(report_date,"%Y-%m-%d %H:%M:%S") &lt;BR /&gt;
| where shift1 &amp;gt;= "07:00:00" AND shift1 &amp;lt;"16:00:00" (SOMETHING HAS TO BE CHANGED HERE, I'm comparing time with string atm)&lt;BR /&gt;
|stats count(INCIDENTE) (I dont really remember what goes here, but not relevant, is just a count...)&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 05:05:29 GMT</pubDate>
    <dc:creator>caiomozer</dc:creator>
    <dc:date>2020-09-30T05:05:29Z</dc:date>
    <item>
      <title>How to check if a time field is between two hour values?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-check-if-a-time-field-is-between-two-hour-values/m-p/480017#M82315</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have a situation where I need to check if a time field, 'report_date' in format "%Y-%m-%d %H:%M:%S" happened between 7 AM and 4 PM of that same day. I cant figure out how to do that comparison. I dont know how to get the hour value from my report_date field.&lt;/P&gt;

&lt;P&gt;I'm trying to do that so I can make a filter to see how many reports were made in a specific period of the day so I can tell which shift recieved the report (the recieving time is not the same as the event time in splunk in that particular scenario), and I need to filter by shift.&lt;/P&gt;

&lt;P&gt;So far what I did:&lt;BR /&gt;
index=raw_maximo INCIDENTE=I* GR_RESP="OPERACAO"&lt;BR /&gt;
| eval shift1=strptime(report_date,"%Y-%m-%d %H:%M:%S") &lt;BR /&gt;
| where shift1 &amp;gt;= "07:00:00" AND shift1 &amp;lt;"16:00:00" (SOMETHING HAS TO BE CHANGED HERE, I'm comparing time with string atm)&lt;BR /&gt;
|stats count(INCIDENTE) (I dont really remember what goes here, but not relevant, is just a count...)&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 05:05:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-check-if-a-time-field-is-between-two-hour-values/m-p/480017#M82315</guid>
      <dc:creator>caiomozer</dc:creator>
      <dc:date>2020-09-30T05:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a time field is between two hour values?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-check-if-a-time-field-is-between-two-hour-values/m-p/480018#M82316</link>
      <description>&lt;P&gt;Your report-date field is in this format -  "%Y-%m-%d %H:%M:%S" &lt;/P&gt;

&lt;P&gt;So an example looks like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2020-04-23 12:12:21 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That hour is already in the format you want.  &lt;CODE&gt;strptime&lt;/CODE&gt; is the wrong tool here.  All you have to do to get what you want is to drop the first 11 characters and keep the last 8.&lt;/P&gt;

&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=raw_maximo INCIDENTE=I* GR_RESP="OPERACAO"
| eval shift1=substr(report_date,12,8)
| where shift1 &amp;gt;= "07:00:00" AND shift1 &amp;lt;"16:00:00" 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Apr 2020 22:13:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-check-if-a-time-field-is-between-two-hour-values/m-p/480018#M82316</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2020-04-23T22:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a time field is between two hour values?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-check-if-a-time-field-is-between-two-hour-values/m-p/480019#M82317</link>
      <description>&lt;P&gt;Is the _time of the event equal to the report_date field?    &lt;/P&gt;

&lt;P&gt;If so, you could do something like this: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=raw_maximo INCIDENTE=I* GR_RESP=OPERACAO" date_hour&amp;gt;=7 date_hour&amp;lt;=16
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;if not, then you can do something like this: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval report_date="2020-04-20 16:20:00|2020-04-20 09:04:20|2020-04-20 17:04:20|2020-04-20 04:20:00|2020-04-20 08:04:20"
| makemv report_date delim="|" | mvexpand report_date | fields - _time
| eval report_date_hour=strftime(strptime(report_date, "%Y-%m-%d %H:%M:%S"), "%H")
| eval is_between_700_and_1600=if(report_date_hour&amp;gt;=7 AND report_date_hour&amp;lt;16, 1, 0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Where you strptime the string to get epoch and strftime the output to get hour by itself... &lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 05:08:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-check-if-a-time-field-is-between-two-hour-values/m-p/480019#M82317</guid>
      <dc:creator>darrenfuller</dc:creator>
      <dc:date>2020-09-30T05:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a time field is between two hour values?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-check-if-a-time-field-is-between-two-hour-values/m-p/480020#M82318</link>
      <description>&lt;P&gt;YES! I can`t believe it was THAT simple! Thank you so much! It worked!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 21:58:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-check-if-a-time-field-is-between-two-hour-values/m-p/480020#M82318</guid>
      <dc:creator>caiomozer</dc:creator>
      <dc:date>2020-04-24T21:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a time field is between two hour values?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-check-if-a-time-field-is-between-two-hour-values/m-p/480021#M82319</link>
      <description>&lt;P&gt;@caiomozer -  It's always easiest to see someone ELSE's issues.  Can't tell you the number of hours we've spent chasing things like that over the decades.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2020 15:35:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-check-if-a-time-field-is-between-two-hour-values/m-p/480021#M82319</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2020-04-30T15:35:16Z</dc:date>
    </item>
  </channel>
</rss>

