Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
TodaysDate Property

Calendar.TodaysDate Property

Gets or sets the value for today's date.

[Visual Basic]
Public Property TodaysDate As DateTime
[C#]
public DateTime TodaysDate {get; set;}
[C++]
public: __property DateTime get_TodaysDate();
public: __property void set_TodaysDate(DateTime);
[JScript]
public function get TodaysDate() : DateTime;
public function set TodaysDate(DateTime);

Property Value

A System.DateTime object that contains the value that the Calendar control considers to be today's date. If this property is not explicitly set, this date will be the date on the server.

Remarks

Use the TodaysDate property to determine today's date. You can also use this property to programmatically set the value for today's date on the Calendar control. This property is set using a System.DateTime object.

Note   This date may need to be adjusted to accommodate users who are in a different time zone.

The appearance of date specified by the TodaysDate property can be customized by using the TodayDayStyle property.

Note   If the VisibleDate property is not set, the date specified by the TodaysDate property determines which month is displayed in the Calendar control.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the TodaysDate property to programmatically set the value for today's date on the Calendar control.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <script language="VB" runat="server">

        Sub Selection_Change(sender As Object, e As EventArgs)
            Calendar1.TodaysDate = Calendar1.SelectedDate
            Label1.Text = "Today's Date is now " & Calendar1.TodaysDate.ToShortDateString()
        End Sub 'Selection_Change

   </script>

</head>     
<body>

   <form runat="server">

      <h3>Calendar Example</h3>

      Select a date on the Calendar control to use as today's date.<br><br>

      <asp:Calendar ID="Calendar1" runat="server"  
           SelectionMode="Day" 
           ShowGridLines="True" 
           OnSelectionChanged="Selection_Change">

         <SelectedDayStyle BackColor="Yellow"
                           ForeColor="Red">
         </SelectedDayStyle>

      </asp:Calendar> 

      <hr><br>

      <asp:Label id="Label1" runat=server />

   </form>
</body>
</html>


[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

   <script language="C#" runat="server">

      void Selection_Change(Object sender, EventArgs e) 
      {
         Calendar1.TodaysDate = Calendar1.SelectedDate;
         Label1.Text = "Today's Date is now " + Calendar1.TodaysDate.ToShortDateString();
      }

   </script>

</head>     
<body>

   <form runat="server">

      <h3>Calendar Example</h3>

      Select a date on the Calendar control to use as today's date.<br><br>

      <asp:Calendar ID="Calendar1" runat="server"  
           SelectionMode="Day" 
           ShowGridLines="True" 
           OnSelectionChanged="Selection_Change">

         <SelectedDayStyle BackColor="Yellow"
                           ForeColor="Red">
         </SelectedDayStyle>

      </asp:Calendar> 

      <hr><br>

      <asp:Label id="Label1" runat=server />

   </form>
</body>
</html>


[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
<head>

   <script language="JScript" runat="server">

      function Selection_Change(sender : Object, e : EventArgs) 
      {
         Calendar1.TodaysDate = Calendar1.SelectedDate;
         Label1.Text = "Today's Date is now " + Calendar1.TodaysDate.ToShortDateString();
      }

   </script>

</head>     
<body>

   <form runat="server">

      <h3>Calendar Example</h3>

      Select a date on the Calendar control to use as today's date.<br><br>

      <asp:Calendar ID="Calendar1" runat="server"  
           SelectionMode="Day" 
           ShowGridLines="True" 
           OnSelectionChanged="Selection_Change">

         <SelectedDayStyle BackColor="Yellow"
                           ForeColor="Red">
         </SelectedDayStyle>

      </asp:Calendar> 

      <hr><br>

      <asp:Label id="Label1" runat=server />

   </form>
</body>
</html>

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

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Calendar Class | Calendar Members | System.Web.UI.WebControls Namespace | System.DateTime | TodayDayStyle

Show:
© 2015 Microsoft