This documentation is archived and is not being maintained.

MonthCalendar.TodayDate Property

Gets or sets the value that is used by MonthCalendar as today's date.

[Visual Basic]
Public Property TodayDate As DateTime
public DateTime TodayDate {get; set;}
public: __property DateTime get_TodayDate();
public: __property void set_TodayDate(DateTime);
public function get TodayDate() : DateTime;
public function set TodayDate(DateTime);

Property Value

A DateTime representing today's date. The default value is the current system date.


By default, the TodayDate property returns the current system date, and the TodayDateSet property is false. Setting the TodayDate property sets the TodayDateSet property to true and, from that point, the value returned by the TodayDate property is the one the user sets.


[Visual Basic, C#] The following code example demonstrates how to use the TodayDate, SelectionStart and SelectionEnd properties. To run the example, paste the following code in a form containing a MonthCalendar control named MonthCalendar1 and call the ShowAWeeksVacationOneMonthFromToday method from the form's constructor or Load method.

[Visual Basic] 
' Computes a week one month from today.
Private Sub ShowAWeeksVacationOneMonthFromToday()
    Dim today As Date = Me.MonthCalendar1.TodayDate
    Dim vacationMonth As Integer = 1
    If (today.Month < 12) Then
        vacationMonth = today.Month + 1
    End If

    ' Select the week using SelectionStart and SelectionEnd.
    Me.MonthCalendar1.SelectionStart = _
        New Date(today.Year, vacationMonth, today.Day - 1)
    Me.MonthCalendar1.SelectionEnd = _
        New Date(today.Year, vacationMonth, today.Day + 6)
End Sub

// Computes a week one month from today.
private void ShowAWeeksVacationOneMonthFromToday()
    System.DateTime today = this.MonthCalendar1.TodayDate;
    int vacationMonth = 1;
    if (today.Month < 12)
        vacationMonth = today.Month + 1;

    // Select the week using SelectionStart and SelectionEnd.
    this.MonthCalendar1.SelectionStart = 
        new System.DateTime(today.Year, vacationMonth, today.Day-1);
    this.MonthCalendar1.SelectionEnd = 
        new System.DateTime(today.Year, vacationMonth, today.Day+6);

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

MonthCalendar Class | MonthCalendar Members | System.Windows.Forms Namespace | TodayDateSet | ShowToday