Click here to Skip to main content
13,351,156 members (24,356 online)
Click here to Skip to main content
Add your own
alternative version


95 bookmarked
Posted 4 Sep 2007

Recurring Date Generator with Pattern Coding

, 4 Sep 2007
Rate this:
Please Sign up or sign in to vote.
Create recurring dates using a user-defined pattern. Create recurring dates from a coded value that defines what the pattern should be.
Screenshot - ScreenShot01.png


I needed a way to create recurring dates using a given pattern of dates such as every weekday, every Saturday and Monday, etc. I couldn't find any sample code on the web other than what you can purchase, so I made this library.

This library not only creates recurring dates but it also returns a coded value that you can store to at a later date, create the same recurring date pattern and adjust the values as needed. This ability to alter the pattern or add more dates to the end of the returned values is what I consider to be a real world requirement. Creating recurring dates is not the issue when creating a pattern of dates, it's being able to store that pattern's design value so it can be used to alter the dates at a later date.

Using the coded pattern value, or Series Info as I call it in this article, you can edit appointment dates similar to those found in Microsoft Outlook. When editing an event in Outlook, you're asked if this is for the current date or the entire series. If you don't have the series date format pattern it's impossible to load up the date controls in the correct format so they match what you first used when you created the recurring dates. This library gives you the ability to do this using the Series Info returned value.


I needed a way to create recurring dates and be able to edit them or adjust the values at a later date.

Using the code

You can open the source solution for a complete sample application that uses the RecurrenceGenerator assembly.

The RecurrenceGenerator library exposes Daily, Weekly, Monthly, and Yearly RecurrenceSettings classes that inherit from RecurrenceSettings class. All the classes have the same constructors.

The constructors allow for:

  1. Start Date (No ending date)
  2. Start Date, End Date (defined ending date)
  3. Start Date, Number of Occurrences (create only x-number of dates)

The constructors are constructed in such a way that you have to, at a minimum, give a Start Date.

/// <span class="code-SummaryComment"><summary></span>
/// Get dates by Start date only. This is for no ending date values.
/// <span class="code-SummaryComment"></summary></span>
/// <span class="code-SummaryComment"><param name="startDate"></param></span>
public DailyRecurrenceSettings(DateTime startDate) : base(startDate) { }

/// <span class="code-SummaryComment"><summary></span>
/// Get dates by Start and End date boundaries.
/// <span class="code-SummaryComment"></summary></span>
/// <span class="code-SummaryComment"><param name="startDate"></param></span>
/// <span class="code-SummaryComment"><param name="endDate"></param></span>
public DailyRecurrenceSettings(DateTime startDate, DateTime endDate) : 
         base(startDate, endDate) { }

/// <span class="code-SummaryComment"><summary></span>
/// Get dates by Start date and number of occurrences.
/// <span class="code-SummaryComment"></summary></span>
/// <span class="code-SummaryComment"><param name="startDate"></param></span>
/// <span class="code-SummaryComment"><param name="numberOfOccurrences"></param></span>
public DailyRecurrenceSettings(DateTime startDate, int numberOfOccurrences) : 
         base(startDate, numberOfOccurrences) { }

The dates are returned in an object called RecurrenceValues. This object is returned by making a call to GetValues([various params based on type of RecurrenceSettings]).

Once the dates are returned, you can use them to list the values such as those in the sample application.

Screenshot - ScreenShot02.png

This workspace shows the dates that were generated by the previous tabs date pattern. The "Series Info" readonly text box shows you the return value that you would store with each date event in your application. Storing this value allows you to create the next date in the pattern as well as generate all the values and adjust them as needed.

Screenshot - ScreenShot05.png

This tab of the sample application allows you to adjust the original Series Info value and create a new set of values. This is the real world in that you may need to extend the date values you're looking at in your calendar control. You might also need to show the next date for the month that's being viewed in your UI control in Winforms.

This third tab allows you to adjust:

  • Start Date
  • Number of occurrences
  • End Date
  • View the definition of the Series Info value. See screen below for example.
Screenshot - ScreenShot06.png

Clicking the "Def." button will bring up a viewer to explain what each Series Info value means. The definitions are different for each pattern (daily, weekly, monthly, yearly).

Screenshot - ScreenShot04.png

This tab shows you the object that can be returned by passing in the Series Info into the RecurrenceHelper shared function GetFriendlySeriesInfo(string seriesInfo).

The Series Info value is different for each date pattern type such as daily, weekly, etc. Each RecurrenceSettings class has a method to view the breakdown of the coded value. This is reached by a call to the RecurrenceHelper.GetPatternDefinition(string seriesInfo).

Points of Interest

Making the sample application helped in the testing process of the date generation. Making a prototype was a good tool to ensure that the RecurrenceGenerator library created the correct values.


  • 7 September, 2007: Added the ability to return a modified series of dates using an existing Series Info value and modified Start Date


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Victor Boba
Software Developer (Senior) BOCA Software Technologies, Inc.
United States United States
.NET Developer in Garner, North Carolina. Specializing in WinForms development in C#, VB.Net.

CEO/Founder BOCA Software Technologies, Inc.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Khalil-Salah16-Aug-17 22:30
memberKhalil-Salah16-Aug-17 22:30 
QuestionGet Position of SIngle Event Date Pin
JoeJoe8757716-May-16 22:07
memberJoeJoe8757716-May-16 22:07 
AnswerRe: Get Position of SIngle Event Date Pin
Garth J Lancaster16-May-16 22:53
professionalGarth J Lancaster16-May-16 22:53 
GeneralRe: Get Position of SIngle Event Date Pin
JoeJoe8757716-May-16 23:14
memberJoeJoe8757716-May-16 23:14 
QuestionAnyone still working with this? Anyone know of any bug since last release? Pin
Kebrite28-Jul-15 5:11
memberKebrite28-Jul-15 5:11 
GeneralMy vote of 5 Pin
NisHtRk15-Feb-14 5:15
memberNisHtRk15-Feb-14 5:15 
GeneralMy vote of 5 Pin
Norbert Haberl27-Jan-14 2:32
memberNorbert Haberl27-Jan-14 2:32 
GeneralGreat Concept Pin
Raavis13-Aug-13 0:47
memberRaavis13-Aug-13 0:47 
QuestionExecellent !!!! Pin
Member 194328325-Jul-13 0:32
memberMember 194328325-Jul-13 0:32 
GeneralMy vote of 5 Pin
Member 194328325-Jul-13 0:30
memberMember 194328325-Jul-13 0:30 
QuestionHow can I set the time Pin
LozGemachet19-Jun-13 8:30
memberLozGemachet19-Jun-13 8:30 
QuestionDoes this project work with web based applications Pin
ochiha_ita19-Oct-12 7:16
memberochiha_ita19-Oct-12 7:16 
Questionrecur weekly not working Pin
Shivapragasam17-Jun-12 20:58
memberShivapragasam17-Jun-12 20:58 
AnswerRe: recur weekly not working Pin
Member 36963833-Aug-12 4:28
memberMember 36963833-Aug-12 4:28 
GeneralRe: recur weekly not working Pin
erozenblat22-Oct-13 23:43
membererozenblat22-Oct-13 23:43 
GeneralRe: recur weekly not working Pin
Zokrit31-Oct-13 5:50
memberZokrit31-Oct-13 5:50 
GeneralIs there a newer Version which works with EndDateType.NoEndDate ? Pin
Bombias15-Apr-11 2:48
memberBombias15-Apr-11 2:48 
GeneralDate pattern not working correctly for week days Pin
monisshamsi24-Dec-09 0:23
membermonisshamsi24-Dec-09 0:23 

Its really helpful.....

But there is 1 problem occuring.......

Like...As for weekly section i am mentioning that a particular person has to come for 2 weeks on these days i.e (Mon,Tue,Wed,Thu,Fri,Sun) for 5 no. of times(take it as any no.)/(Occurences) then the dates are getting generated correctly in the lstdates by pressing generate dates button but if i am also mentioning Sat along with all these days, then its generating a wrong pattern( like if i am also inputting period more than 1).............

One more if i just want a recurring of appointments only on sat,then mentioning the no. of occurences(take any no. like 5) and mentioning the no. on textbox1(like 1) the dates are getting generated ,But soon after these dates get generated,what the problem is comming is that when i again change the textbox1 value to 2, 3 or either any no. ,then its not generating the correct result,its just overriding the previous result....and not showing the correct pattern....

Kindly check it out..............ASAP......
If u can resolve this problem just mail me update on my ID i.e

GeneralRe: Date pattern not working correctly for week days Pin
Victor Boba24-Dec-09 4:00
memberVictor Boba24-Dec-09 4:00 
GeneralRe: Date pattern not working correctly for week days Pin
monisshamsi25-Dec-09 20:01
membermonisshamsi25-Dec-09 20:01 
GeneralIt's very nice. Pin
iamnon26-May-09 7:32
memberiamnon26-May-09 7:32 
GeneralGood coding Pin
TomChris24-Oct-08 13:11
memberTomChris24-Oct-08 13:11 
GeneralRe: Good coding Pin
Victor Boba24-Oct-08 13:59
memberVictor Boba24-Oct-08 13:59 
GeneralRe: Good coding Pin
Nagarajan Mohan12-Mar-09 20:02
memberNagarajan Mohan12-Mar-09 20:02 
GeneralExcellent!! Pin
Etienne Ngandu18-Feb-08 4:31
memberEtienne Ngandu18-Feb-08 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 4 Sep 2007
Article Copyright 2007 by Victor Boba
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid