Convert text in asp textbox into Date (C#) : Date Time « Language Basics « ASP.Net






Convert text in asp textbox into Date (C#)

<%@ Page Language="C#" Debug="true" %>
<script runat="server">

    void Page_Load()
    {
        if (Page.IsPostBack) {
            DateTime MyDate;
            MyDate = Convert.ToDateTime(txtInput.Text);
            lblOut.Text = Convert.ToString(MyDate);
        }
    }

</script>
<html>
<head>
<title>Creating Variables Example</title>
</head>
<body>
    <form runat="server">
    Please enter a date, such as 10/31/2006
    <asp:TextBox runat="server" ID="txtInput">10/31/2006</asp:TextBox><br/>
    <asp:Button runat="server" Text="Button"></asp:Button><br/>
    Date is: 
    <asp:Label runat="server" ID="lblOut"/><br/>
    </form>
</body>
</html>
           
       








Related examples in the same category

1.Year() function (VB.net)
2.Get Today date (VB.net)
3.Get Time Of a Day (VB.net)
4.DateTime constructor: no parameters (VB.net)
5.DateTime constructor: year, month, day (VB.net)
6.DateTime constructor: year, month, day, hour, minute, second (VB.net)
7.DateTime constructor: milli-second (VB.net)
8.Assign Date and Integer value to asp:textbox without converting (VB.net)
9.Get Hour, Second and Minute from Current time (VB.net)
10.Assign date in form of '#3/6/2003#' to asp:Label (VB.net)
11.Convert Current date to Long Time String and set to asp:Label (VB.net)
12.Convert Current date to Long Date String and set to asp:Label (VB.net)
13.Convert Current date to Short Time String and set to asp:Label (VB.net)
14.Convert Current date to Short Date String and set to asp:Label (VB.net)
15.Time limit validation (C#)
16.new DateTime() (C#)
17.DateTime constructor: year, month, day (C#)
18.DateTime constructor: year, month, day, hour, minute, second (C#)
19.DateTime constructor: milli-seconds (C#)
20.Date Comparison (C#)
21.Date calculation: plus 7 days (C#)