<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!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>Age</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
BirthDaydate:
</td>
<td>
<asp:TextBox runat="server" ID="txtBirthDayDate" ></asp:TextBox>
</td>
<td>
Number Of days:
</td>
<td>
<asp:TextBox runat="server" ID="txtResult"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Button runat="server" ID="btnDays" OnClick="CountNumberOfdays_Click" Text="CheckDates" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Inherits="_Default" %>
<!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>Age</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
BirthDaydate:
</td>
<td>
<asp:TextBox runat="server" ID="txtBirthDayDate" ></asp:TextBox>
</td>
<td>
Number Of days:
</td>
<td>
<asp:TextBox runat="server" ID="txtResult"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Button runat="server" ID="btnDays" OnClick="CountNumberOfdays_Click" Text="CheckDates" />
</td>
</tr>
</table>
</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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CountNumberOfdays_Click(object sender, EventArgs e)
{
DateTime date = Convert.ToDateTime(txtBirthDayDate.Text);
DateTime BirthDayDate = new DateTime(date.Year, date.Month, date.Day);
DateTime Todaydate = DateTime.Now;
TimeSpan ts = Todaydate - BirthDayDate;
float differenceInDays = ts.Days;
float age = differenceInDays / 365;
txtResult.Text = age.ToString();
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CountNumberOfdays_Click(object sender, EventArgs e)
{
DateTime date = Convert.ToDateTime(txtBirthDayDate.Text);
DateTime BirthDayDate = new DateTime(date.Year, date.Month, date.Day);
DateTime Todaydate = DateTime.Now;
TimeSpan ts = Todaydate - BirthDayDate;
float differenceInDays = ts.Days;
float age = differenceInDays / 365;
txtResult.Text = age.ToString();
}
}
Result:
Enter Date in first Text box:
1-02-2013
Age:
0.5123287
No comments:
Post a Comment