<%@ 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>
Originally Posted on February 25, 2013
Last Updated on October 26, 2015
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.