<?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 calculate time for a given day of week? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578760#M201699</link>
    <description>&lt;P&gt;Here is an example. &amp;nbsp;If my given_date is 2021-12-19, I want to know if this is earlier than/equal to, or later than any December Fridays. &amp;nbsp;In the calendar:&lt;/P&gt;&lt;TABLE border="1" width="54.70130997474747%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="20.5536386051498%"&gt;Fridays of December 2021&lt;/TD&gt;&lt;TD width="34.149504254486004%"&gt;2021-12-19&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20.5536386051498%"&gt;-2 weeks (12-3)&lt;/TD&gt;&lt;TD width="34.149504254486004%"&gt;later than&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20.5536386051498%"&gt;-1 week (12-10)&lt;/TD&gt;&lt;TD width="34.149504254486004%"&gt;later than&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20.5536386051498%"&gt;this week (12-17)&lt;/TD&gt;&lt;TD width="34.149504254486004%"&gt;earlier than&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20.5536386051498%"&gt;+1 week (12-24)&lt;/TD&gt;&lt;TD width="34.149504254486004%"&gt;earlier than&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20.5536386051498%"&gt;+2 weeks (12-31)&lt;/TD&gt;&lt;TD width="34.149504254486004%"&gt;earlier than&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;As mentioned, it is possible to do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval date_comp = if((5 - strftime(time(), "%w") + offset_wk * 7) * 86400 &amp;gt; given_date, "later", "earlier")&lt;/LI-CODE&gt;&lt;P&gt;Here, offset_wk is the look-ahead or look-back value from today as shown in the illustrated table; current week is 0, previous week is -1, next week is 1, and so on. &amp;nbsp;But this seems to be a lot of code for a simple ask.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Dec 2021 15:07:54 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2021-12-17T15:07:54Z</dc:date>
    <item>
      <title>How to calculate time for a given day of week?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578693#M201681</link>
      <description>&lt;P&gt;How to perform calculations on a given day of week? &amp;nbsp;Specifically, I want to compare a given time value, say given_date, with a given day of week of a given week, say, next Friday.&lt;/P&gt;&lt;P&gt;If I want to perform the calculation, say, for a week from now, I can use&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;if(given_date &amp;gt; time() + 7 * 86400, "later", "earlier")&lt;/P&gt;&lt;P&gt;(This can be easily adjusted for beginning of day, etc.) &amp;nbsp;If today is Friday, the above will tell me whether given_date is earlier than or later than next Friday. &amp;nbsp;But if today is Monday, it only tells me whether it is earlier or later than next Monday.&lt;/P&gt;&lt;P&gt;For event data, I can extract day of week from date_wday. &amp;nbsp;Is there a calculator/function to do that for arbitrary time value? &amp;nbsp;I suppose I can use strftime(time(), "%w") &amp;nbsp;to determine delta from desired day of week, then add/subtract whole weeks to the desired day of week. (Unlike date_wday, strftime() gives a numeric value that is easy for calculation.) &amp;nbsp;Is there a more direct way?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 02:08:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578693#M201681</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2021-12-17T02:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time for a given day of week?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578735#M201688</link>
      <description>&lt;P&gt;I am not sure I understand what you are trying to do. If today is a Wednesday, and your given day is Friday, do you want to determine the date of the next Friday (this week), or the Friday next week? Similarly, if the given day is Monday, do you want to determine the date of the next Monday (next week) or the Monday at least a week away (the following week)?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 10:59:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578735#M201688</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-12-17T10:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time for a given day of week?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578760#M201699</link>
      <description>&lt;P&gt;Here is an example. &amp;nbsp;If my given_date is 2021-12-19, I want to know if this is earlier than/equal to, or later than any December Fridays. &amp;nbsp;In the calendar:&lt;/P&gt;&lt;TABLE border="1" width="54.70130997474747%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="20.5536386051498%"&gt;Fridays of December 2021&lt;/TD&gt;&lt;TD width="34.149504254486004%"&gt;2021-12-19&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20.5536386051498%"&gt;-2 weeks (12-3)&lt;/TD&gt;&lt;TD width="34.149504254486004%"&gt;later than&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20.5536386051498%"&gt;-1 week (12-10)&lt;/TD&gt;&lt;TD width="34.149504254486004%"&gt;later than&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20.5536386051498%"&gt;this week (12-17)&lt;/TD&gt;&lt;TD width="34.149504254486004%"&gt;earlier than&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20.5536386051498%"&gt;+1 week (12-24)&lt;/TD&gt;&lt;TD width="34.149504254486004%"&gt;earlier than&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20.5536386051498%"&gt;+2 weeks (12-31)&lt;/TD&gt;&lt;TD width="34.149504254486004%"&gt;earlier than&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;As mentioned, it is possible to do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval date_comp = if((5 - strftime(time(), "%w") + offset_wk * 7) * 86400 &amp;gt; given_date, "later", "earlier")&lt;/LI-CODE&gt;&lt;P&gt;Here, offset_wk is the look-ahead or look-back value from today as shown in the illustrated table; current week is 0, previous week is -1, next week is 1, and so on. &amp;nbsp;But this seems to be a lot of code for a simple ask.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 15:07:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578760#M201699</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2021-12-17T15:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time for a given day of week?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578766#M201704</link>
      <description>&lt;P&gt;Surely 19th is later than 17th?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval givendate=strptime("2021-12-19","%F")
| eval week=mvrange(-2,3)
| mvexpand week
| eval week=printf("%+d",week)
| eval date=relative_time(givendate,week."w@w-1w+5d")
| eval date_comp=if(date&amp;lt;givendate,"later","earlier")
| fieldformat date=strftime(date,"%A %F")
| fieldformat givendate=strftime(givendate,"%A %F")&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 17 Dec 2021 15:31:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578766#M201704</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-12-17T15:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time for a given day of week?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578785#M201710</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Surely 19th is later than 17th?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":face_with_tears_of_joy:"&gt;😂&lt;/span&gt;my bad&lt;/P&gt;&lt;P&gt;relative_time() is exactly the syntax shortcut I was looking for!&lt;/P&gt;&lt;P&gt;For anyone who may have a similar need, the key point is that relative_time() accepts expressive syntax like "w@w-1w+5d", so intention is no longer obscured. ("w-1w" is not exactly needed.) &amp;nbsp;Necessary code is captured in these two lines:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval date=relative_time(givendate,week."w@+5d")
| eval date_comp=if(date&amp;lt;givendate,"later","earlier")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Here, givendate is a numeric representation of the date, and week is a string representation of the desired offset (in weeks); 5 (numeric for Friday) can also be any other number that represents a day of week.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 18:14:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578785#M201710</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2021-12-17T18:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time for a given day of week?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578794#M201713</link>
      <description>&lt;P&gt;Actually, it is just the -1w that is not needed if the calculation is done against now instead of givendate (my bad). The&amp;nbsp;@w is still need to snap to the beginning of the week that now() is in before adjusting by -2 through +2 weeks plus 5 (for Friday)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| fields - _time
| eval givendate=strptime("2021-12-19","%F")
| eval week=mvrange(-2,3)
| mvexpand week
| eval week=printf("%+d",week)
| eval date=relative_time(now(),week."w@w+5d")
| eval date_comp=if(date&amp;lt;givendate,"later","earlier")
| fieldformat date=strftime(date,"%A %F")
| fieldformat givendate=strftime(givendate,"%A %F")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 19:07:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-for-a-given-day-of-week/m-p/578794#M201713</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-12-17T19:07:24Z</dc:date>
    </item>
  </channel>
</rss>

