<?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: Number of day per month in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/573656#M199912</link>
    <description>&lt;P&gt;I have tried many of the solutions offered in several posts and ended up with this:&lt;/P&gt;&lt;P&gt;| eventstats dc(date_mday) AS daysInMonth&lt;/P&gt;&lt;P&gt;Unless i'm mistaken, the date_* fields are automatically generated in splunk (at least all the data i've seen has them) and this was the easiest and most reliable method I found.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Nov 2021 18:12:16 GMT</pubDate>
    <dc:creator>sjbriggs</dc:creator>
    <dc:date>2021-11-04T18:12:16Z</dc:date>
    <item>
      <title>Number of day per month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30283#M6126</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;

&lt;P&gt;A very simple question but I can't find the answer anywhere: how to get the number of day (28, 30 or 31) for any month?&lt;/P&gt;

&lt;P&gt;I have for now a cumbersome (and false for bissextile years) way to do this (lookup table for each month, setting nb_day for each month).&lt;/P&gt;

&lt;P&gt;I couldn't find any topic or question about this.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;

&lt;P&gt;Guilhem&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 09:01:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30283#M6126</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2013-02-13T09:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: Number of day per month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30284#M6127</link>
      <description>&lt;P&gt;There's no inbuilt command that provides this. A lookup, like the one you're already using, would probably be the cleanest way to do it.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 09:21:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30284#M6127</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-02-13T09:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Number of day per month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30285#M6128</link>
      <description>&lt;P&gt;I am surprised no one ask for this before.&lt;/P&gt;

&lt;P&gt;Thanks for the answer. I will set up the lookup for bissextile year and post it when it's done.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 09:26:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30285#M6128</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2013-02-13T09:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Number of day per month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30286#M6129</link>
      <description>&lt;P&gt;As suggested, there is no built-in way to do this, so a lookup table seems the easiest way to do it. Here is the file I use for the lookup:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"date_year","date_month","date_numericmonth","day_number"
2017,january,01,31
2017,february,02,28
2017,march,03,31
2017,april,04,30
2017,may,05,31
2017,june,06,30
2017,july,07,31
2017,august,08,31
2017,september,09,30
2017,october,10,31
2017,november,11,30
2017,december,12,31
2016,january,01,31
2016,february,02,29
2016,march,03,31
2016,april,04,30
2016,may,05,31
2016,june,06,30
2016,july,07,31
2016,august,08,31
2016,september,09,30
2016,october,10,31
2016,november,11,30
2016,december,12,31
2015,january,01,31
2015,february,02,28
2015,march,03,31
2015,april,04,30
2015,may,05,31
2015,june,06,30
2015,july,07,31
2015,august,08,31
2015,september,09,30
2015,october,10,31
2015,november,11,30
2015,december,12,31
2014,january,01,31
2014,february,02,28
2014,march,03,31
2014,april,04,30
2014,may,05,31
2014,june,06,30
2014,july,07,31
2014,august,08,31
2014,september,09,30
2014,october,10,31
2014,november,11,30
2014,december,12,31
2013,january,01,31
2013,february,02,28
2013,march,03,31
2013,april,04,30
2013,may,05,31
2013,june,06,30
2013,july,07,31
2013,august,08,31
2013,september,09,30
2013,october,10,31
2013,november,11,30
2013,december,12,31
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Feb 2013 09:44:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30286#M6129</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2013-02-13T09:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: Number of day per month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30287#M6130</link>
      <description>&lt;P&gt;You can do this programattically with a macro.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[days_in_month(1)]
args = month
definition = [ | gentimes [ | gentimes start=-1| eval start="$month$" | rex field=start (?&amp;lt;month&amp;gt;.*?)/(?&amp;lt;year&amp;gt;.*) | eval start=month."/01/".year | return start ] [ | gentimes start=-1| eval start="$month$" | rex field=start (?&amp;lt;month&amp;gt;.*?)/(?&amp;lt;year&amp;gt;.*) | eval end=strftime(relative_time(strptime(month."/01/".year, "%m/%d/%y"),"+1mon@mon"),"%m/%d/%y") | return end ] increment=1d | stats count as search | return $search ]
iseval = 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example usage :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; * | head 1 | eval days=`days_in_month(month="02/12")` | table days
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;days  
------  
29
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Feb 2013 17:00:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30287#M6130</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-02-13T17:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Number of day per month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30288#M6131</link>
      <description>&lt;P&gt;OK, that's maybe the best automated solution, I completely forgot about arguments in macro, thanks for finding out this one!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2013 17:08:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30288#M6131</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2013-02-14T17:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: Number of day per month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30289#M6132</link>
      <description>&lt;P&gt;Total number of days in current month can be calculated using following eval statement:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;eval lastDay=strftime(relative_time(relative_time(now(),"+1mon@mon"),"-1d@d"),"%d")&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Change "now()" to any other date (epoch time) to calculate the number of days in month specific to custom date.&lt;/P&gt;

&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:22:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30289#M6132</guid>
      <dc:creator>vganjare</dc:creator>
      <dc:date>2020-09-28T17:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Number of day per month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30290#M6133</link>
      <description>&lt;P&gt;You can get a table of all months and the number of days they have as follows:&lt;/P&gt;

&lt;P&gt;eval DayNr=strftime(_time,"%d") | timechart span=1mon max(DayNr) as NrOfDays | eval Month=strftime(_time,"%B %Y") | table Month NrOfDays&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:04:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30290#M6133</guid>
      <dc:creator>sanderdenheijer</dc:creator>
      <dc:date>2020-09-28T19:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: Number of day per month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30291#M6134</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| eval today=now(), 
  nextMonth=relative_time(today,"+1Mon@Mon"), 
  minusOneDay=relative_time(nextMonth,"-1d@d"), 
  daysInMonth=strftime(minusOneDay,"%e")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;daysInMonth will have the value you seek&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 02:44:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/30291#M6134</guid>
      <dc:creator>cstump_splunk</dc:creator>
      <dc:date>2019-02-13T02:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Number of day per month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/573656#M199912</link>
      <description>&lt;P&gt;I have tried many of the solutions offered in several posts and ended up with this:&lt;/P&gt;&lt;P&gt;| eventstats dc(date_mday) AS daysInMonth&lt;/P&gt;&lt;P&gt;Unless i'm mistaken, the date_* fields are automatically generated in splunk (at least all the data i've seen has them) and this was the easiest and most reliable method I found.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2021 18:12:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Number-of-day-per-month/m-p/573656#M199912</guid>
      <dc:creator>sjbriggs</dc:creator>
      <dc:date>2021-11-04T18:12:16Z</dc:date>
    </item>
  </channel>
</rss>

