Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You would call IntervalInQuarters as follows:</p> <pre><code>IntervalInQuarters(new DateTime(2007, 10, 10), new DateTime(2009, 10, 11)); </code></pre> <p>The function returns a list of quarter start dates. Note that the range of quarters searched is defined within the function itself. Please edit as appropriate for your situation. They key point is to make sure the interval/quarter intersection logic is right.</p> <pre><code>private List&lt;DateTime&gt; IntervalInQuarters(DateTime myStartDate, DateTime myEndDate) { DateTime quarterStart = new DateTime(2006, 06, 01); DateTime nextQuarterStart = new DateTime(2006, 09, 01); DateTime finalDate = new DateTime(2011, 01, 01); List&lt;DateTime&gt; foundQuarters = new List&lt;DateTime&gt;(); while (quarterStart &lt; finalDate) { // quarter intersects interval if: // its start/end date is within our interval // our start/end date is within quarter interval DateTime quarterEnd = nextQuarterStart.AddDays(-1); if (DateInInterval(myStartDate, quarterStart, quarterEnd) || DateInInterval(myEndDate, quarterStart, quarterEnd) || DateInInterval(quarterStart, myStartDate, myEndDate) || DateInInterval(quarterEnd, myStartDate, myEndDate)) { foundQuarters.Add(quarterStart); } quarterStart = nextQuarterStart; nextQuarterStart = nextQuarterStart.AddMonths(3); } return foundQuarters; } private bool DateInInterval(DateTime myDate, DateTime intStart, DateTime intEnd) { return ((intStart &lt;= myDate) &amp;&amp; (myDate &lt;= intEnd)); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload