using System;
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 string calulateAge(string dateDOB){
int now = int.Parse(DateTime.Today.ToString("yyyyMMdd"));
int dob = int.Parse(dateDOB);
string dif = (now - dob).ToString();
string age = "0";
if (dif.Length > 4)
age = dif.Substring(0, dif.Length - 4);
return age;
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
textBox1.Text = calulateAge(dateTimePicker1.Value.ToString("yyyyMMdd"));
}
}
}