Note that there are some explanatory texts on larger screens.

plurals
  1. POC# comparing dates then decrementing
    text
    copied!<p>ok so this should be simple really but seems I can't get my head around it. I have a table called Dates which has a listing of all dates starting 2012 until its very end. Now when a customer makes reservation, I need to take starting date and ending date, generate the range between them in datetime format, and check each against its equivalent date in table to see capacity. if so, then decrement the capacity by booking requirement. so far I have this code:</p> <pre><code> private List&lt;DateTime&gt; getDateRange(DateTime startDate, DateTime endDate) { if (startDate &gt; endDate) { return null; } List&lt;DateTime&gt; rv = new List&lt;DateTime&gt;(); DateTime tmpDate = startDate; do { rv.Add(tmpDate); tmpDate = tmpDate.AddDays(1); } while (tmpDate &lt;= endDate); return rv; } </code></pre> <p>The code is supposed to generate a list with dates in range and is called later in this function:</p> <pre><code>public void checkDateRange(DateTime startDate, DateTime endDate) { //need to check each element in the list against the table DateTest: //changing the parameters of parse will give error. Require type handling //First, extract the elements: DateTime StartingDate = DateTime.Parse("02/25/2007"); DateTime EndingDate = DateTime.Parse("03/06/2007"); foreach (DateTime date in getDateRange(StartingDate, EndingDate)) { date.ToShortDateString(); } //rest of code should go here... } </code></pre> <p>am thinking more like retrieve whole set from table DateTest, then in a loop (not sure which) I would go about checking if x = y these are the dates. Any code illustration would be highly appreciated. Regards,</p>
 

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