Mark This Response as Answer -- Chandu http://www.dotnetfunda.com/images/dnfmvp.gif
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CalculateAge.aspx.cs" Inherits="WebApplication1.CalculateAge" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="txtDate" runat="server" /> <asp:Button Text="Click" runat="server" id="btnAge" onclick="btnAge_Click"/> <asp:Label Text="" ID="lblAge" runat="server" /> </div> </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1 { public partial class CalculateAge : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnAge_Click(object sender, EventArgs e) { DateTime date = DateTime.Parse(txtDate.Text); DateTime defaultDate = DateTime.Parse("07-31-2012"); TimeSpan days = defaultDate.Subtract(date); double NumofYears = days.TotalDays; lblAge.Text = NumofYears.ToString() + " Days"; } } }
Login to post response