How to calculate years and months of experience from the months of experience in asp.net C#
In this article, we will count year and month on the
base of month of experience only that's means How to calculate years and months
of experience from the months of experience value. Many time we need to count
the experience of employee in years and month when we put only months. Suppose
we have entered in textbox 25 then we will get output in 2 Year 1 Month form.
Source Code:-
<%@
Page Language="C#" AutoEventWireup="true" CodeFile="MathDivRem .aspx.cs" Inherits="MathDivRem_"
%>
<!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>
<fieldset style="width: 600px;">
<legend>How to
calculate years and months of experience from the months of experience
value</legend>
<asp:TextBox ID="txtExperience" placeholder="Months of experience" runat="server"
AutoPostBack="True"
OnTextChanged="txtExperience_TextChanged"></asp:TextBox>
<asp:Label ID="lbresult" runat="server" ForeColor="#669900"></asp:Label>
</fieldset>
</div>
</form>
</body>
</html>
Code behind(C#):-
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using
System.Web.UI.WebControls;
public partial class MathDivRem_ : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
}
public string CalculateExperience(Int32
monthsOfExperience)
{
int
numberOfYears, numberOfMonths;
numberOfYears = Math.DivRem(monthsOfExperience, 12, out
numberOfMonths);
return string.Format("{0}
{1}", numberOfYears + " Year",
numberOfMonths > 1 ? numberOfMonths + "
Months" : numberOfMonths + "
Month");
}
protected void txtExperience_TextChanged(object sender, EventArgs
e)
{
lbresult.Text = CalculateExperience(Convert.ToInt32(txtExperience.Text.Trim()));
}
}
Out-Put:-
How to calculate years and months of experience from the months of experience in asp.net C#
Reviewed by NEERAJ SRIVASTAVA
on
3:32:00 PM
Rating:
Thank you for providing this exclusive blog with us. This was really an amazing blog post. I really enjoyed by reading your blog post.
ReplyDeleteDotnet Training in Chennai
thanks for sharing wondeful blog with us. its really more helpful to our institute candidates to get aware some useful knowledge keep sharing more information.
ReplyDeleteDot Net training in Chennai
Thank you for sharing such a informative post.. Java Training Institute in Chennai | Java Training Institute in Velachery.
ReplyDeleteGood and nice blog post, thanks for sharing your information.. it is very useful to me.. keep rocks and updating
ReplyDeleteDot Net Training in chennai