<%@ Page Language="C#" %> <%@ Import Namespace="System" %> <%@ Import Namespace="System.Collections.Generic" %> <%@ Import Namespace="System.Linq" %> <%@ Import Namespace="System.Web" %> <%@ Import Namespace="System.Web.UI" %> <%@ Import Namespace="System.Web.UI.WebControls" %> <script runat="server"> protected void Button1_Click(object sender, EventArgs e) { DateTime date1 = Convert.ToDateTime(TextBox1.Text); DateTime date2 = new DateTime(DateTime.Now.Year - 1, 12, 18); // See http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx for DateTime Help int nResult = DateTime.Compare(date1, date2); if (nResult < 0) { result.InnerHtml = "Is earlier than"; } else if (nResult == 0) { result.InnerHtml = "Is the same time as"; } else { result.InnerHtml = "Is later than"; } } </script> <form runat="server"> <asp:textbox id="TextBox1" runat="server"></asp:textbox> <asp:button id="Button1" runat="server" text="Test" onclick="Button1_Click" /> <div id="result" runat="server"></div> </form>
Last Updated on October 26, 2015