# 2.2.1.44.1.1 Calculating the Value of the FirstDateTime Field

This section provides details about how to calculate the value of the FirstDateTime field of the RecurrencePattern structure, specified in section 2.2.1.44.1, for a daily, weekly, monthly, or yearly recurring series. The value of FirstDateTime is in minutes measured from a reference time, which is midnight January 1, 1601 for a Gregorian calendar, to the date that is being specified.

The values of the StartDate, Period, and FirstDOW fields of the RecurrencePattern structure are used in the calculations.

DAILY

For a daily recurring series, the value of the FirstDateTime field is equal to the value of the StartDate field modulo the value of the Period field. The value of the FirstDateTime field for a daily recurring series will be a value between 0 (zero) and (period – 1440). The calculation of the value is summarized by the following formula:

``` FirstDateTime = StartDate % Period
```

WEEKLY

For a weekly recurring series, the value of the FirstDateTime field is calculated as follows:

1. Determine the date of the beginning of the week that contains the date indicated by the StartDate field. In other words, this date is that of the first day of the week in which the first event of the recurring series occurs. This date depends on the value of the FirstDOW field, which specifies the day that begins a calendar week. This dependency is illustrated in the figure and example following this procedure.

2. Calculate the number of minutes between midnight, January 1, 1601, and midnight of the date that was determined in step 1.

3. Calculate the number of minutes between recurrences. This value is the number of minutes per week, 10080, multiplied by the value of the Period field.

4. The value of the FirstDateTime field is equal to the result from step 2 modulo the result from step 3.

The calculation of the value of the FirstDateTime field is summarized by the following formula:

``` FirstDateTime = (result from step 2) % (Period * 10080)
```

The following figure and example show how the date of the first event week, which is determined in step 1, depends on the value of the FirstDOW field.

Figure 1: Date of the event week depends on the day that begins a calendar week

If the value of the FirstDOW field indicates that weeks begin on Sunday (0x00000000) and the value of the StartDate field indicates April 12, 2007, which falls on Thursday, as the date of the first event of the recurring series, then the date of the first event week is April 8, 2007, as shown in Calendar A in the preceding figure. However, if the value of the FirstDOW field indicates that weeks begin on Wednesday (0x00000003), the date of the first event week is April 11, 2007, as shown in Calendar B in the preceding figure.

MONTHLY or YEARLY

For a monthly recurring series or a yearly recurring series, the value of the FirstDateTime field is calculated as follows:

1. Determine the date of the beginning of the month that contains the date indicated by the StartDate field. In other words, this date is that of the first day of the month containing the first event of the recurring series.

2. Calculate the number of calendar months between midnight of January 1, 1601, and midnight of the date that was determined in step 1.

3. Calculate the offset of months within the year of 1601. This value is equal to the result from step 2 modulo the value of the Period field. The calculation is summarized by the following formula:

``` offset of months within the year of 1601 = (result from step 2) % Period
```
4. Calculate the number corresponding to the month that contains the first event within the year of 1601 by adding one to the result from step 3. The calculation of this value is summarized by the following formula:

``` month within the year of 1601 = ((result from step 2) % Period) + 1
```
5. The value of the FirstDateTime field is equal the number of minutes between midnight of the first day of the month that was determined in step 4 and midnight January 1, 1601.

Show: