Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You probably want a function that takes two DateTime objects (The start date and the end date) and some interval in between events. You can then use the <a href="http://msdn.microsoft.com/en-us/library/system.datetime.adddays.aspx" rel="nofollow">DateTime.AddDays(double value)</a> function to generate all of the in-between dates. To get every other week, your interval would be 14. You would keep adding 14 days until the date you got was after your end date.</p> <pre><code>//Create a list of DateTimes including the start date, with the specified //number of days in between each item in the list. public static IList&lt;DateTime&gt; GetRepeatingEvents(DateTime start, DateTime end, int intervalInDays) { List&lt;DateTime&gt; allEvents = new List&lt;DateTime&gt;(); allEvents.Add(start); //Make sure the start date is included in the list of dates! var tempDate = start; while (tempDate &lt;= end) //Less than or Equals means the end date will be added as well { tempDate = tempDate.AddDays(intervalInDays); allEvents.Add(tempDate); } return allEvents; } </code></pre> <p>You'll need to be a bit careful if your start and end dates contain a Time component as well. For example, if:</p> <ul> <li>Your start date was July 7, 2012 <strong>10:30 AM</strong></li> <li>Your end date was July 28, 2012 <strong>9:00 AM</strong></li> <li>Your interval was one week (7 days)</li> </ul> <p>Then above function would not include a July 28 date in the list because 21 days after July 7th 10:30 AM is July 28th 10:30 AM which would not satisfy the conditional in <code>while(tempDate &lt;= end)</code> because end occurs at 9:00 AM</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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