<?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 achieve search to match the fields with current date? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/631664#M219384</link>
    <description>&lt;P&gt;Doesn't ISO 8601 use the exact 10-character "yyyy-mm-dd" representation for dates? &amp;nbsp;That's exactly what my code snippet is designed to do. &amp;nbsp;substr is just a shortcut to compare dates. &amp;nbsp;Or do yo mean if the fields are &lt;EM&gt;not&lt;/EM&gt; in ISO 8601 format?&lt;/P&gt;</description>
    <pubDate>Tue, 21 Feb 2023 07:24:15 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2023-02-21T07:24:15Z</dc:date>
    <item>
      <title>How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/629022#M218487</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Need a search query to find the either if&amp;nbsp; first_find and last_find values matches with the current date should raise an alert .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;first_find last_find fields are in&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;2020-04-30T13:18:13.000Z&lt;/TD&gt;
&lt;TD&gt;2023-01-15T14:12:18.000Z&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;format need this in&amp;nbsp;&amp;nbsp;2020-04-30 format&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Instead of receiving all the alerts we require, if today's date matches the first _find or the last_find, raise an alert&lt;BR /&gt;*todays date will change every day do not bound that with actual todays date*&lt;BR /&gt;&lt;BR /&gt;note : last_find&amp;nbsp; , first_find are multi valued fields..&lt;/P&gt;
&lt;P&gt;Thanks...&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 18:00:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/629022#M218487</guid>
      <dc:creator>AL3Z</dc:creator>
      <dc:date>2023-01-31T18:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/629080#M218510</link>
      <description>&lt;P&gt;If first_find and last_find are strings and the format is as illustrated, you can simply match with now().&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| where strftime(now(), "%F") == substr(first_find, 1, 10) OR strftime(now(), "%F") == substr(last_find, 1, 10)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 01 Feb 2023 05:36:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/629080#M218510</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-02-01T05:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/631587#M219364</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;using this sub string function&amp;nbsp; do we get desired output if the first find and last find fields in events are in &lt;SPAN&gt;ISO 8601 format ? how we can normalize it ??&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 14:33:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/631587#M219364</guid>
      <dc:creator>AL3Z</dc:creator>
      <dc:date>2023-02-20T14:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/631664#M219384</link>
      <description>&lt;P&gt;Doesn't ISO 8601 use the exact 10-character "yyyy-mm-dd" representation for dates? &amp;nbsp;That's exactly what my code snippet is designed to do. &amp;nbsp;substr is just a shortcut to compare dates. &amp;nbsp;Or do yo mean if the fields are &lt;EM&gt;not&lt;/EM&gt; in ISO 8601 format?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 07:24:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/631664#M219384</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-02-21T07:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/631675#M219389</link>
      <description>&lt;P&gt;hi,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;My field values&amp;nbsp;"last_find": "2023-02-15T16:15:52.506Z"&lt;BR /&gt;"first_find": "2021-06-07T09:04:09.130Z" are in utc time and my search head is&amp;nbsp; ist time zone.&lt;BR /&gt;do we need to convert the utc to ist time zone to get desired alerts ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 08:28:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/631675#M219389</guid>
      <dc:creator>AL3Z</dc:creator>
      <dc:date>2023-02-21T08:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/631802#M219457</link>
      <description>&lt;P&gt;Yes, you need to explain any such data characteristics in order for others to be helpful. &amp;nbsp;If I'm looking up correctly, IST is 5.5 hours ahead of UTC.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| where strftime(now() - 19800, "%F") == substr(first_find, 1, 10) OR strftime(now() - 19800, "%F") == substr(last_find, 1, 10)&lt;/LI-CODE&gt;&lt;P&gt;This will match date in UTC. &amp;nbsp;You also forget to say which date you want to match. &amp;nbsp;Although for date match, the difference can probably be neglected. &amp;nbsp;But if you really want, you can force the match to go the other way.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval first_find = strptime(first_find, "%FT%H:%M:%S.%3N%Z")
| eval last_find = strptime(last_find, "%FT%H:%M:%S.%3N%Z")
| where strftime(now(), "%F") == strftime(19800 + first_find, "%F") OR strftime(now(), "%F") == strftime(19800 + last_find, "%F")&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 22 Feb 2023 07:42:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/631802#M219457</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-02-22T07:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/631807#M219459</link>
      <description>&lt;P&gt;It depends on what you want with those dates. If you have a UTC date, you can parse it to an epoch time with&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval utc_epoch=strptime(utc_date, "%FT%T.%Q%Z")&lt;/LI-CODE&gt;&lt;P&gt;Then you can make whatever comparisons against 'today' you need to make. Is "today" UTC or IST?&lt;/P&gt;&lt;P&gt;If a last_find is&amp;nbsp;&lt;SPAN&gt;2023-02-15T21:15:52.506Z, is that 15 Feb "today" in UTC or ""yesterday" for IST?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;when you reformat that utc epoch using strftime, it will be done in YOUR timezone&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval date=strftime(utc_epoch, "%F")&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 22 Feb 2023 08:14:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/631807#M219459</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-02-22T08:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/632003#M219519</link>
      <description>&lt;P&gt;&lt;SPAN&gt;My understanding is that the objective is to identify the first_detect or last_detect matches with&amp;nbsp; the current date based on the provided snapshot. I now comprehend that modifying the UTC format is unnecessary as Splunk will handle it automatically. Prior to comparing the time with fields, we must convert it to epoch format right.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 15:20:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/632003#M219519</guid>
      <dc:creator>AL3Z</dc:creator>
      <dc:date>2023-02-26T15:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/632055#M219546</link>
      <description>&lt;P&gt;That is correct. &amp;nbsp;For most time/date calculations, it is advantageous to use epoch or another numeric representation. &amp;nbsp;Your ask is about matching only dates, therefore the last step to extract the "date" portion from the time. &amp;nbsp;If the data source and search head share the same time zone, there's some shortcut you can take as I illustrated in the first answer. (It is rather surprising that your search head would run something other than UTC. &amp;nbsp;Unless you are running it on a personal device, it is always advantageous to use the same time zone across your deployment, and UTC is often the easiest choice.)&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 17:25:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/632055#M219546</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-02-23T17:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/632077#M219552</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Can we use this alternative search&amp;nbsp;&lt;/P&gt;&lt;P&gt;| eval todays_date=now()&lt;/P&gt;&lt;P&gt;| eval todays_date=strftime(todays_date,"%Y-%m-%d"), first_detected=strftime(strptime(first_detected,"%Y-%m-%dT%H:%M:%S.%QZ"),"%Y-%m-%d"), last_detected=strftime(strptime(last_detected,"%Y-%m-%dT%H:%M:%S.%QZ"),"%Y-%m-%d")&lt;BR /&gt;| where todays_date=first_detected OR todays_date=last_detected&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2023 12:30:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/632077#M219552</guid>
      <dc:creator>AL3Z</dc:creator>
      <dc:date>2023-02-25T12:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/632269#M219631</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Using a named variable todays_date makes the code more readable and improves maintainability. &amp;nbsp;That is good. &amp;nbsp;But&amp;nbsp;&lt;/SPAN&gt;this search would give the same result as my first answer because it doesn't take into account the time zone difference. &amp;nbsp;Here is a breakdown.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;Semantically, "%Y-%m-%d" is identical to the shortcut "%F".&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Mathematically, strftime(strptime(first_detected,"%Y-%m-%dT%H:%M:%S.%QZ"),"%Y-%m-%d") always gives the date in the original timezone, therefore the exact same output as substr(first_detected, &amp;nbsp;1, 10). &amp;nbsp;The disadvantage, of course, is more compute and memory cost.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;You need to decide whether you want todays_date to be in the data source's time zone (UTC) or the search heads' time zone. &amp;nbsp;If you want to align with search heads, you need to also ask: are all search head in IST, or will it change from head to head?&lt;/P&gt;&lt;P&gt;Assuming you want todays_date to be in IST, you can do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval todays_date=relative_time(now(), +5.5h)
| eval todays_date=strftime(todays_date,"%Y-%m-%d"), first_detected=strftime(strptime(first_detected,"%Y-%m-%dT%H:%M:%S.%QZ"),"%Y-%m-%d"), last_detected=strftime(strptime(last_detected,"%Y-%m-%dT%H:%M:%S.%QZ"),"%Y-%m-%d")
| where todays_date=first_detected OR todays_date=last_detected&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2023 19:05:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/632269#M219631</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-02-25T19:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/632275#M219633</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;All my SH's are in utc,only my user sh in ist.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 00:42:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/632275#M219633</guid>
      <dc:creator>AL3Z</dc:creator>
      <dc:date>2023-02-26T00:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to achieve search to match the fields with current date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/632277#M219634</link>
      <description>&lt;P&gt;In other words, you cannot predetermine the user's locale. &amp;nbsp;If so, you need to first calculate offset at the user's search head.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval offset = strptime("2000-01-01Z", "%F%Z") - strptime("2000-01-01", "%F")
| eval todays_date=strftime(now() + offset,"%Y-%m-%d"), first_detected=strftime(strptime(first_detected,"%Y-%m-%dT%H:%M:%S.%QZ"),"%Y-%m-%d"), last_detected=strftime(strptime(last_detected,"%Y-%m-%dT%H:%M:%S.%QZ"),"%Y-%m-%d")
| where todays_date=first_detected OR todays_date=last_detected&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 05:12:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-achieve-search-to-match-the-fields-with-current-date/m-p/632277#M219634</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-02-26T05:12:33Z</dc:date>
    </item>
  </channel>
</rss>

