In: Computer Science
Using ASP.NET create an Age Calculator; which can determine an age according to a given date of birth. The calculated age will be displayed in years, months, weeks, days, hours, minutes, and seconds. How old are you in years, or months, or weeks, or days, or minutes, or seconds. The only input parameter is the birth date then the user will know his age
Design
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Agecalculator1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 233px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:Label ID="Label1" runat="server" Text="Enter the Date of
Birth ."></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"
Width="359px"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="calander.png" Height="36px" Width="33px"/>
<asp:Calendar ID="Calendar1" runat="server" BackColor="White"
BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"
Height="180px" Width="200px">
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True"
Font-Size="7pt" />
<NextPrevStyle VerticalAlign="Bottom" />
<OtherMonthDayStyle ForeColor="#808080" />
<SelectedDayStyle BackColor="#666666" Font-Bold="True"
ForeColor="White" />
<SelectorStyle BackColor="#CCCCCC" />
<TitleStyle BackColor="#999999" BorderColor="Black"
Font-Bold="True" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<WeekendDayStyle BackColor="#FFFFCC" />
</asp:Calendar>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Label ID="lblage"
runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Button ID="btnCalculate" runat="server" Text="Calculate"
Width="160px" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
DesignView
Coding
Public Class WebForm1
Inherits System.Web.UI.Page
Dim dob As Date
Dim days, month, year, hour, minutes, second As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Calendar1.Visible = False
End Sub
Protected Sub btnCalculate_Click(sender As Object, e As
EventArgs) Handles btnCalculate.Click
dob = Convert.ToDateTime(TextBox1.Text)
year = DateDiff(DateInterval.Year, dob, Now) ''calculate year
here
month = DateDiff(DateInterval.Month, dob, Now) 'calculate month
here
days = DateDiff(DateInterval.Day, dob, Now) 'calculate days
here
hour = DateDiff(DateInterval.Hour, dob, Now) 'calculate hour
here
minutes = DateDiff(DateInterval.Minute, dob, Now) 'calculate Minute
here
second = DateDiff(DateInterval.Second, dob, Now) 'calculate Second
here
lblage.Text = "Year ::" + Convert.ToString(year) + " Months ::" +
Convert.ToString(month) + " Days ::" + days.ToString + " Hour :- "
+ hour.ToString + " Minutes :-" + minutes.ToString + " Second " +
second.ToString
''output display here
End Sub
Protected Sub ImageButton1_Click(sender As Object, e As
ImageClickEventArgs) Handles ImageButton1.Click
If Calendar1.Visible = False Then
Calendar1.Visible = True
Else
Calendar1.Visible = False
End If
End Sub
Protected Sub Calendar1_SelectionChanged(sender As Object, e As
EventArgs) Handles Calendar1.SelectionChanged
dob = Calendar1.SelectedDate.ToString("MM/dd/yyyy hh:mm:ss")
TextBox1.Text = dob.ToString
End Sub
End Class
Output
if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........