<?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 get last weekday of last month and check logs for an date field in the logs having that value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546734#M154997</link>
    <description>&lt;P&gt;Fieldformat doesn't change the value of the field or change it from an epoch time to a string for example. I think what you want is to keep events where the date is the last weekday of the month?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=* | eval date=strptime(date,"%Y-%m-%d")
| eval last_day=relative_time(date,"+1mon@mon-1d")
| eval dotw=tonumber(strftime(last_day,"%w"))
| eval adjust=case(dotw=0,2,dotw=6,1,1==1,0)
| eval last_weekday=last_day-(adjust * 24 * 60 * 60)
| where date=last_weekday&lt;/LI-CODE&gt;&lt;P&gt;This assumes date in your events is a string that needs to be parsed into an epoch date. If it is already an epoch date, then you don't need the first eval&lt;/P&gt;</description>
    <pubDate>Mon, 05 Apr 2021 17:39:05 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2021-04-05T17:39:05Z</dc:date>
    <item>
      <title>How to get last weekday of last month and check logs for an date field in the logs having that value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546705#M154987</link>
      <description>&lt;P&gt;I have something that runs every day but i need to see it only for previous EOM which is also a weekday&lt;/P&gt;&lt;P&gt;I have a field as date =2021-03-31 in the logs&lt;/P&gt;&lt;P&gt;I am not sure how can I get the previous EOM(weekday) and compare it with my date field value.&lt;/P&gt;&lt;P&gt;I have already tried answer given here but has not helped.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.splunk.com/t5/Archive/Function-To-Return-Last-Weekday/m-p/172413#M25201" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Archive/Function-To-Return-Last-Weekday/m-p/172413#M25201&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Any help appreciated.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 12:36:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546705#M154987</guid>
      <dc:creator>ashutoshwalke</dc:creator>
      <dc:date>2021-04-05T12:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last weekday of last month and check logs for an date field in the logs having that value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546710#M154988</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults | eval _raw=strftime(relative_time(now(),"@mon-1d"),"%w")&lt;/LI-CODE&gt;&lt;P&gt;1-5 are weekdays, 0 is Sunday, 6 is Saturday&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 13:17:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546710#M154988</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-04-05T13:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last weekday of last month and check logs for an date field in the logs having that value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546713#M154990</link>
      <description>&lt;P&gt;Hi, Thank you for your response.&lt;/P&gt;&lt;P&gt;From your query I get the day number and is not helpful.&lt;/P&gt;&lt;P&gt;I need the date of last weekday in previous month, say 2021-03-31 and then I need to check in my logs looking in the date field if date=2021-03-31 is present or not. If yes , I use the logs.&lt;/P&gt;&lt;P&gt;Logically may be it could be something like below, but I am not getting the correct syntax or way of doing it,&lt;/P&gt;&lt;P&gt;| makeresults&lt;BR /&gt;| eval current_month_last_day=relative_time(now(),"@mon-1d") | fieldformat current_month_last_day=strftime(current_month_last_day,"%Y-%m-%d")| eval day_value = case(date_wday=="saturday", "1d", date_wday="sunday", "2d") | eval current_month_last_day=relative_time(current_month_last_day-day_value) | table current_month_last_day&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Explanation&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;------------------------------------------------------------------------------------------------------------------------------------&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1. | makeresults&lt;BR /&gt;| eval current_month_last_day=relative_time(now(),"@mon-1d") | fieldformat current_month_last_day=strftime(current_month_last_day,"%Y-%m-%d") --- &lt;STRONG&gt;with this is get the last date of previous month&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2. | eval day_value = case(date_wday=="saturday", "1d", date_wday="sunday", "2d") | eval current_month_last_day=relative_time(current_month_last_day-day_value)--- &lt;STRONG&gt;here i try to check if it is not a weekend, if it happens to be then minus 1 day or 2 day from the date calculated in step 1.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;------------------------------------------------------------------------------------------------------------------------------------&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 13:58:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546713#M154990</guid>
      <dc:creator>ashutoshwalke</dc:creator>
      <dc:date>2021-04-05T13:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last weekday of last month and check logs for an date field in the logs having that value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546720#M154991</link>
      <description>&lt;P&gt;I would disagree - it is useful if you know what to do with it&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults | eval last_day=relative_time(now(),"-1mon@mon-1d")
| eval dotw=tonumber(strftime(last_day,"%w"))
| eval adjust=case(dotw=0,2,dotw=6,1,1==1,0)
| eval last_weekday=last_day-(adjust * 24 * 60 * 60)
| fieldformat last_weekday=strftime(last_weekday,"%a %Y-%m-%d")&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 05 Apr 2021 15:03:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546720#M154991</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-04-05T15:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last weekday of last month and check logs for an date field in the logs having that value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546731#M154994</link>
      <description>&lt;P&gt;Thanks a lot, that worked like a charm &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Just one question, I am unable to compare it with my date field in the log using a WHERE clause. I could see both the dates are in same format.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;index=* | eval last_day=relative_time(now(),"+0mon@mon-1d")&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval dotw=tonumber(strftime(last_day,"%w"))&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval adjust=case(dotw=0,2,dotw=6,1,1==1,0)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval last_weekday=last_day-(adjust * 24 * 60 * 60)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| fieldformat last_weekday=strftime(last_weekday,"%Y-%m-%d") | table last_weekday date&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;When I run above query it does gives me a table as below, also when i search just using date=2021-03-31 it does gives me the results.&lt;/P&gt;&lt;P&gt;last_weekday&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;2021-03-31&lt;/TD&gt;&lt;TD&gt;2021-04-02&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2021-03-31&lt;/TD&gt;&lt;TD&gt;2021-03-23&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2021-03-31&lt;/TD&gt;&lt;TD&gt;2021-03-23&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried doing below to convert my date field just in case,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| fieldformat date=strftime(date,"%Y-%m-%d")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;but that didn't&amp;nbsp;help.&lt;/P&gt;&lt;P&gt;Can you advise ?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 17:17:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546731#M154994</guid>
      <dc:creator>ashutoshwalke</dc:creator>
      <dc:date>2021-04-05T17:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last weekday of last month and check logs for an date field in the logs having that value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546733#M154996</link>
      <description>&lt;P&gt;I was able to do it after I change fieldformat to eval here&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| fieldformat last_weekday=strftime(last_weekday,"%Y-%m-%d") &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;TO&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;| eval last_weekday=strftime(last_weekday,"%Y-%m-%d")&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 17:38:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546733#M154996</guid>
      <dc:creator>ashutoshwalke</dc:creator>
      <dc:date>2021-04-05T17:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last weekday of last month and check logs for an date field in the logs having that value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546734#M154997</link>
      <description>&lt;P&gt;Fieldformat doesn't change the value of the field or change it from an epoch time to a string for example. I think what you want is to keep events where the date is the last weekday of the month?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=* | eval date=strptime(date,"%Y-%m-%d")
| eval last_day=relative_time(date,"+1mon@mon-1d")
| eval dotw=tonumber(strftime(last_day,"%w"))
| eval adjust=case(dotw=0,2,dotw=6,1,1==1,0)
| eval last_weekday=last_day-(adjust * 24 * 60 * 60)
| where date=last_weekday&lt;/LI-CODE&gt;&lt;P&gt;This assumes date in your events is a string that needs to be parsed into an epoch date. If it is already an epoch date, then you don't need the first eval&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 17:39:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-last-weekday-of-last-month-and-check-logs-for-an-date/m-p/546734#M154997</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-04-05T17:39:05Z</dc:date>
    </item>
  </channel>
</rss>

