JG Vimalan's Blog

It is all about coding!

Calculate age using C#.NET

Suppose user enter’s his date of birth that is in ‘mm/dd/yyyy’ format,

for example, 

DateTime dob = Convert.ToDateTime(“08/03/1981”); 

int years = DateTime.Now.Year – dob.Year; 

dob = dob.AddYears(years); 

if (DateTime.Now.CompareTo(dob) < 0)

   Years–; 

int age = Years; // Output: Exact age.

Advertisements

October 9, 2009 - Posted by | C#.NET

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: