<?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: comparing datetime with current datettime in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690753#M235255</link>
    <description>&lt;P&gt;Both are set in the events as a field&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jun 2024 19:51:50 GMT</pubDate>
    <dc:creator>AnanthaS</dc:creator>
    <dc:date>2024-06-14T19:51:50Z</dc:date>
    <item>
      <title>comparing datetime with current datettime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690613#M235198</link>
      <description>&lt;P&gt;following query yields no results:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=shared_data source="lambda:maintenance_window_handler" sourcetype="httpevent" | where eventStartsFrom &amp;lt;= now() and eventEndsAt &amp;gt;= now()&lt;/LI-CODE&gt;
&lt;P&gt;but&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=shared_data source="lambda:maintenance_window_handler" sourcetype="httpevent" | where eventStartsFrom &amp;lt;= now() &lt;/LI-CODE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=shared_data source="lambda:maintenance_window_handler" sourcetype="httpevent" | where eventEndsAt &amp;gt;= now()&lt;/LI-CODE&gt;
&lt;P&gt;both works individually. All comparisons are made against epoch date format.&lt;/P&gt;
&lt;P&gt;Can someone help me understand as what mistake I am doing here.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 14:04:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690613#M235198</guid>
      <dc:creator>AnanthaS</dc:creator>
      <dc:date>2024-06-13T14:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: comparing datetime with current datettime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690615#M235199</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/267385"&gt;@AnanthaS&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;probably the issue is that the boolean AND operato must be in uppercase.&lt;/P&gt;&lt;P&gt;then, don't use where after the main search, your search is slower!&lt;/P&gt;&lt;P&gt;put all the search terms in the main search&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=shared_data source="lambda:maintenance_window_handler" sourcetype="httpevent" (eventStartsFrom &amp;lt;= now() AND eventEndsAt &amp;gt;= now())&lt;/LI-CODE&gt;&lt;P&gt;If your search continue to not working, probably you haven't any event where you can find both the fields&amp;nbsp;&lt;SPAN&gt;entStartsFrom and eventEndsAt and you have to group them using the stats command.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Ciao.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Giuseppe&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 13:24:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690615#M235199</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2024-06-13T13:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: comparing datetime with current datettime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690653#M235218</link>
      <description>&lt;P&gt;Are eventStartsFrom and eventEndsAt both set in the events you want to retrieve or are they in separate but correlated events?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 18:12:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690653#M235218</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-06-13T18:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: comparing datetime with current datettime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690753#M235255</link>
      <description>&lt;P&gt;Both are set in the events as a field&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 19:51:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690753#M235255</guid>
      <dc:creator>AnanthaS</dc:creator>
      <dc:date>2024-06-14T19:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: comparing datetime with current datettime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690755#M235256</link>
      <description>&lt;P&gt;Just tried making AND in Upper case, but didnt wrk&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 20:10:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690755#M235256</guid>
      <dc:creator>AnanthaS</dc:creator>
      <dc:date>2024-06-14T20:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: comparing datetime with current datettime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690759#M235257</link>
      <description>&lt;P&gt;Can you post some dataset as well as test time that you think should yield results but did not? (To eliminate the complexity of the test, you can compare with a fixed epoch time instead of now().) &amp;nbsp;I ran the following and your where command gives 2 to 3 outputs depending on when in the calendar minute the emulation runs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=10
| streamstats count as offset
| eval _time = relative_time(_time, "-" . offset . "min"),
  eventStartsFrom = relative_time(_time, "+" . (10 - offset) . "min"),
  eventEndsAt = relative_time(eventStartsFrom, "+5min")
| eval _time = now()
``` data emulation abvove ```
| fieldformat eventStartsFrom = strftime(eventStartsFrom, "%F %T")
| fieldformat eventEndsAt = strftime(eventEndsAt, "%F %T")
| where eventStartsFrom &amp;lt;= now() and eventEndsAt &amp;gt;= now()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One sample output is&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;_time&lt;/TD&gt;&lt;TD&gt;eventEndsAt&lt;/TD&gt;&lt;TD&gt;eventStartFrom&lt;/TD&gt;&lt;TD&gt;offset&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="166.046875px" height="25px"&gt;2024-06-14 13:49:36&lt;/TD&gt;&lt;TD width="166.046875px" height="25px"&gt;2024-06-14 13:54:36&lt;/TD&gt;&lt;TD width="166.0625px" height="25px"&gt;2024-06-14 13:49:36&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="166.046875px" height="25px"&gt;2024-06-14 13:49:36&lt;/TD&gt;&lt;TD width="166.046875px" height="25px"&gt;2024-06-14 13:52:36&lt;/TD&gt;&lt;TD width="166.0625px" height="25px"&gt;2024-06-14 13:47:36&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="166.046875px" height="25px"&gt;2024-06-14 13:49:36&lt;/TD&gt;&lt;TD width="166.046875px" height="25px"&gt;2024-06-14 13:50:36&lt;/TD&gt;&lt;TD width="166.0625px" height="25px"&gt;2024-06-14 13:45:36&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;another output is&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;_time&lt;/TD&gt;&lt;TD&gt;eventEndsAt&lt;/TD&gt;&lt;TD&gt;eventStartFrom&lt;/TD&gt;&lt;TD&gt;offset&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2024-06-14 13:53:11&lt;/TD&gt;&lt;TD&gt;2024-06-14 13:56:12&lt;/TD&gt;&lt;TD&gt;2024-06-14 13:51:12&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2024-06-14 13:53:11&lt;/TD&gt;&lt;TD&gt;2024-06-14 13:54:12&lt;/TD&gt;&lt;TD&gt;2024-06-14 13:49:12&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;The final output uses _time field to display now().&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 20:55:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690759#M235257</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-06-14T20:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: comparing datetime with current datettime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690783#M235271</link>
      <description>&lt;P&gt;Thanks for your time and help. I am posting my solution down in thread. Your suggestion of posting datasets I will take care in my future posts. though so as it is easy to get help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2024 06:26:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690783#M235271</guid>
      <dc:creator>AnanthaS</dc:creator>
      <dc:date>2024-06-15T06:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: comparing datetime with current datettime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690784#M235272</link>
      <description>&lt;P&gt;I realize that now() function does not give 13 digits of epoch date time and only 10 digits length where as my other two fields viz. eventStartsFrom and eventEndsAt are having 13 digits.&lt;/P&gt;&lt;P&gt;eventStartsFrom = 1718394600000&lt;BR /&gt;now = 1718432273&lt;BR /&gt;eventEndsAt= 1718740200000&lt;/P&gt;&lt;P&gt;Hence, I multiplied now() by 1000 and then wrote this query below&lt;/P&gt;&lt;P&gt;index=shared_data source="lambda:maintenance_window_handler" sourcetype="httpevent" | eval nowdate = (now() * 1000 )| eval diffBeginDates = (nowdate - eventStartsFrom) | eval diffEndDates = (eventEndsAt - nowdate) | where diffBeginDates &amp;gt; 0 and diffEndDates &amp;gt; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After this the query behaved as intended. Thanks all for the help. (This thread can be closed now.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2024 06:30:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690784#M235272</guid>
      <dc:creator>AnanthaS</dc:creator>
      <dc:date>2024-06-15T06:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: comparing datetime with current datettime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690786#M235273</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;I realize that now() function does not give 13 digits of epoch date time and only 10 digits length where as my other two fields viz. eventStartsFrom and eventEndsAt are having 13 digits.&lt;P&gt;eventStartsFrom = 1718394600000&lt;BR /&gt;now = 1718432273&lt;BR /&gt;eventEndsAt= 1718740200000&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You mean the two extracted fields are not epoch time, but epoch time expressed in milliseconds. &amp;nbsp;Generally, it's a better idea to bring data to match now() so semantics is clearer. &amp;nbsp;But considering that multiplication is more efficient than division, doing the opposite is perhaps better. &amp;nbsp;I suggest to name now() * 1000 more semantically expressive, such as &lt;EM&gt;now_ms&lt;/EM&gt; instead of calling it something "date". &amp;nbsp;This helps future maintenance.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2024 06:45:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690786#M235273</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-06-15T06:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: comparing datetime with current datettime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690790#M235277</link>
      <description>&lt;P&gt;&lt;SPAN&gt;eventEndsAt&amp;nbsp; and&amp;nbsp;eventStartsFrom&amp;nbsp; are epoch date format expresssed in milliseconds and now() is also epoch date format but not expressed in milliseconds format. I will rename the columns, thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2024 08:13:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690790#M235277</guid>
      <dc:creator>AnanthaS</dc:creator>
      <dc:date>2024-06-15T08:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: comparing datetime with current datettime</title>
      <link>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690791#M235278</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/267385"&gt;@AnanthaS&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;good for you, see next time!&lt;/P&gt;&lt;P&gt;Ciao and happy splunking&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;&lt;P&gt;P.S.: Karma Points are appreciated by all the contributors &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2024 09:34:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/comparing-datetime-with-current-datettime/m-p/690791#M235278</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2024-06-15T09:34:23Z</dc:date>
    </item>
  </channel>
</rss>

