Click or drag to resize

ScheduleHelperGetValidMonthsBySchedule Method

Gets a list of valid dates related to months within a scheduled range.

Namespace:  Xcalibur.Helpers
Assembly:  Xcalibur.Helpers (in Xcalibur.Helpers.dll) Version: 1.0.1.0 (1.0.1.0)
Syntax
public static DateTime[] GetValidMonthsBySchedule(
	DateTime startDate,
	DateTime endDate,
	int numberOfMonths,
	int dayOfMonth
)

Parameters

startDate
Type: SystemDateTime
The start date.
endDate
Type: SystemDateTime
The end date.
numberOfMonths
Type: SystemInt32
The number of months to skip per date.
dayOfMonth
Type: SystemInt32
The day of the month the event occurs.

Return Value

Type: DateTime
Examples
C#
 1static void Main(string[] args)
 2{
 3    var startDate = new DateTime(2018, 2, 17);
 4    var endDate = startDate.AddYears(2);
 5
 6    // Occurs on the 5th day of every month until the end date
 7    var dates = ScheduleHelper.GetValidMonthsBySchedule(startDate, endDate, 1, 5);
 8    Console.WriteLine($"By date range ({dates.Length}):");
 9    foreach (var date in dates)
10    {
11        Console.WriteLine($"{date:MM/dd/yyy, dddd}");
12    }
13
14    // Spacer
15    Console.WriteLine("");
16
17    // Occurs on the 5th day of every month until 20 occurrences have been reached.
18    var dates2 = ScheduleHelper.GetValidMonthsByOccurrence(startDate, 1, 5, 20, 2);
19    Console.WriteLine($"By # of occurrences ({dates2.Length}):");
20    foreach (var date in dates2)
21    {
22        Console.WriteLine($"{date:MM/dd/yyyy, dddd}");
23    }
24
25    // Hold
26    Console.Read();
27}
28
29/* Result:
30 *
31 * By date range (25):
32 * 02/05/2018, Monday
33 * 03/05/2018, Monday
34 * 04/05/2018, Thursday
35 * 05/05/2018, Saturday
36 * 06/05/2018, Tuesday
37 * 07/05/2018, Thursday
38 * 08/05/2018, Sunday
39 * 09/05/2018, Wednesday
40 * 10/05/2018, Friday
41 * 11/05/2018, Monday
42 * 12/05/2018, Wednesday
43 * 01/05/2019, Saturday
44 * 02/05/2019, Tuesday
45 * 03/05/2019, Tuesday
46 * 04/05/2019, Friday
47 * 05/05/2019, Sunday
48 * 06/05/2019, Wednesday
49 * 07/05/2019, Friday
50 * 08/05/2019, Monday
51 * 09/05/2019, Thursday
52 * 10/05/2019, Saturday
53 * 11/05/2019, Tuesday
54 * 12/05/2019, Thursday
55 * 01/05/2020, Sunday
56 * 02/05/2020, Wednesday
57 * 
58 * By # of occurrences (20):
59 * 02/05/2018, Monday
60 * 03/05/2018, Monday
61 * 04/05/2018, Thursday
62 * 05/05/2018, Saturday
63 * 06/05/2018, Tuesday
64 * 07/05/2018, Thursday
65 * 08/05/2018, Sunday
66 * 09/05/2018, Wednesday
67 * 10/05/2018, Friday
68 * 11/05/2018, Monday
69 * 12/05/2018, Wednesday
70 * 01/05/2019, Saturday
71 * 02/05/2019, Tuesday
72 * 03/05/2019, Tuesday
73 * 04/05/2019, Friday
74 * 05/05/2019, Sunday
75 * 06/05/2019, Wednesday
76 * 07/05/2019, Friday
77 * 08/05/2019, Monday
78 * 09/05/2019, Thursday
79 */
See Also