<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to get a count of data from database between a date range</title><link>https://community.appian.com/discussions/f/data/18020/how-to-get-a-count-of-data-from-database-between-a-date-range</link><description>Hello , 
 I have a column of dates in the table as &amp;quot;09-DEC-19&amp;quot; , i have a requirement to show a count of data between first and last day of month. Say i want to get the count of data from Nov 1st to Nov 30th NOV. 
 
 Same should populate every month.</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to get a count of data from database between a date range</title><link>https://community.appian.com/thread/70951?ContentTypeID=1</link><pubDate>Wed, 11 Dec 2019 14:38:30 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:efbd6162-a504-4872-990d-f68e829dec82</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;good point - i think i wrote the above rules either before eomonth() existed, or at least before I knew about it ;-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a count of data from database between a date range</title><link>https://community.appian.com/thread/70950?ContentTypeID=1</link><pubDate>Wed, 11 Dec 2019 14:32:33 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c834ad24-0e74-4f6f-bb1f-b84ed9d4bea8</guid><dc:creator>normanc</dc:creator><description>&lt;p&gt;There is the eomonth() function too&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  end: eomonth(today(), -1),
  start: date(year(local!end), month(local!end), 1),
  &amp;quot;Between &amp;quot; &amp;amp; local!start &amp;amp; &amp;quot; and &amp;quot; &amp;amp; local!end
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a count of data from database between a date range</title><link>https://community.appian.com/thread/70946?ContentTypeID=1</link><pubDate>Wed, 11 Dec 2019 12:40:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:76e351d6-8ec9-4858-9457-e48f9ef95b02</guid><dc:creator>gauravp0003</dc:creator><description>&lt;p&gt;Thanks Mike.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a count of data from database between a date range</title><link>https://community.appian.com/thread/70872?ContentTypeID=1</link><pubDate>Mon, 09 Dec 2019 13:06:40 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7bd51baa-6679-460e-94b0-c43afe31662f</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;lucky coincidence - i previously wrote expression rules to return the start and end dates for the previous month, adjusting for things like year boundary, leap year, etc.&amp;nbsp; For full robustness you would use the following 3:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;/* GLBL_returnEndDateForMonth */

if(
  or(
    isnull(ri!year),
    isnull(ri!month),
    ri!month &amp;lt; 1,
    ri!month &amp;gt; 12
  ),
  null(),

  a!localVariables(
    
    local!monthlyDayTotals: {
      /* January */ 31,
      /* February */ 28 + if(isleapyear(ri!year),1,0),
      /* March */ 31,
      /* April */ 30,
      /* May */ 31,
      /* June */ 30,
      /* July */ 31,
      /* August */ 31,
      /* September */ 30,
      /* October */ 31,
      /* November */ 30,
      /* December */ 31
    },
    
    local!monthEndDay: index(
      local!monthlyDayTotals,
      ri!month
    ),
      
    local!monthEndDate: date(
      ri!year,
      ri!month,
      local!monthEndDay
    ),
    
    local!monthEndDate
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;/* GLBL_returnPreviousMonthStartDate */

a!localVariables(
  
  local!currentYear: year(ri!date),
  local!previousYear: local!currentYear - 1,
  local!currentMonth: month(ri!date),
  
  local!previousMonth: index(
    {12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
    local!currentMonth
  ),
  
  local!previousMonthYear: if(
    local!currentMonth = 1,
    local!previousYear,
    local!currentYear
  ),
  
  local!previousMonthStartDate: date(
    local!previousMonthYear,
    local!previousMonth,
    1
  ),
  
  local!previousMonthStartDate
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;/* GLBL_returnPreviousMonthEndDate */

a!localVariables(
  
  local!currentYear: year(ri!date),
  local!previousYear: local!currentYear - 1,
  local!currentMonth: month(ri!date),
  
  local!previousMonth: index(
    {12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
    local!currentMonth
  ),
  
  local!previousMonthYear: if(
    local!currentMonth = 1,
    local!previousYear,
    local!currentYear
  ),
  
  local!previousMonthEndDate: rule!GLBL_returnEndDateForMonth(
    year: local!previousMonthYear,
    month: local!previousMonth
  ),
    
  local!previousMonthEndDate
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;After you have these 3 rules installed, you would simply need to change your filters to call the &amp;quot;return previous month start date&amp;quot; and &amp;quot;return previous month end date&amp;quot; rules.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a count of data from database between a date range</title><link>https://community.appian.com/thread/70871?ContentTypeID=1</link><pubDate>Mon, 09 Dec 2019 12:54:19 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9ba96028-6269-47c0-bb80-bcbd72d2682e</guid><dc:creator>gauravp0003</dc:creator><description>&lt;p&gt;yes , correct.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a count of data from database between a date range</title><link>https://community.appian.com/thread/70870?ContentTypeID=1</link><pubDate>Mon, 09 Dec 2019 12:53:32 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b3f3bbc8-aa20-458f-8033-c8514f0394c3</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;So you mean you want it to do like the above filtering, but always automatically show the data for the month right before the current month?&amp;nbsp; IE on January 1st, it would automatically switch to filtering between Dec 1st and 31st, etc?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a count of data from database between a date range</title><link>https://community.appian.com/thread/70869?ContentTypeID=1</link><pubDate>Mon, 09 Dec 2019 12:46:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:52b05eb7-0e9a-4cf9-a81d-ccbc190d3def</guid><dc:creator>gauravp0003</dc:creator><description>&lt;p&gt;type is date only, I have below rule to get a count between a particular month, I want it to be dynamic so every month data it will be updated. in DB data will be of last month, so in December, DB will have data of November month.Currently value is hard coded , i want it to be dynamic.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;a!queryEntity(&lt;br /&gt; entity: cons!ds_cons,&lt;br /&gt; query: a!query(&lt;br /&gt; logicalExpression: a!queryLogicalExpression(&lt;br /&gt; operator: &amp;quot;AND&amp;quot;,&lt;br /&gt; filters:{&lt;br /&gt; a!queryFilter(&lt;br /&gt; field: &amp;quot;date&amp;quot;,&lt;br /&gt; operator: &amp;quot;&amp;lt;=&amp;quot;,&lt;br /&gt; value: todate(&amp;quot;30-NOV-2019&amp;quot;)&lt;br /&gt; ),&lt;br /&gt; a!queryFilter(&lt;br /&gt; field: &amp;quot;date&amp;quot;,&lt;br /&gt; operator: &amp;quot;&amp;gt;=&amp;quot;,&lt;br /&gt; value: todate(&amp;quot;01-NOV-2019&amp;quot;)&lt;br /&gt; )&lt;br /&gt; }&lt;br /&gt; ),&lt;br /&gt; pagingInfo: a!pagingInfo(&lt;br /&gt; 1,&lt;br /&gt; - 1&lt;br /&gt; )&lt;br /&gt; )&lt;br /&gt; ).totalcount&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a count of data from database between a date range</title><link>https://community.appian.com/thread/70868?ContentTypeID=1</link><pubDate>Mon, 09 Dec 2019 12:35:54 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8c915e94-3f0b-45ee-8753-0b62472792cf</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Is there any particular reason you&amp;#39;re not storing dates as a DATE or&amp;nbsp;DATETIME column in the table?&amp;nbsp; That way you would be able to use simple filtering in your query.&amp;nbsp; If possible, I&amp;#39;d suggest either changing the existing column to use the DATE type, or add a secondary column to act as basically a duplicate of the original column but storing the DATE format instead of the text you&amp;#39;re currently using.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>