how and coding for these
explain briefly?? pls
in c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sanjeeb LenkaPosted Dec 2, 2013, 2:58 AM
use this method to calculate age. pass the text box date value to this method it will return the age:
public int Age(DateTime dt)
{
DateTime today = DateTime.Today;
int age = today.Year - dt.Year;
if (dt > today.AddYears(-age))
age--;
return age;
}
Satyapriya NayakPosted Dec 2, 2013, 3:52 AM
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int intYear, intMonth, intDaY;
intYear = Convert.ToInt32(textBox1.Text);
intMonth = Convert.ToInt32(textBox2.Text);
intDaY = Convert.ToInt32(textBox3.Text);
DateTime dtt = new DateTime(intYear, intMonth, intDaY);
DateTime td = DateTime.Now;
int Leap_Year = 0;
for (int i = dtt.Year; i < td.Year; i++)
{
if (DateTime.IsLeapYear(i))
{
++Leap_Year;
}
}
TimeSpan timespan = td.Subtract(dtt);
intDaY = timespan.Days - Leap_Year;
int intResult = 0;
intYear = Math.DivRem(intDaY, 365, out intResult);
intMonth = Math.DivRem(intResult, 30, out intResult);
intDaY = intResult;
MessageBox.Show("Hello dear! You are " + intYear.ToString() + " Year/s " + intMonth + " Month/s " + intDaY + " Day/s");
}
}
}