C# Calculate Age Tutorial with Examples

C# Calculate Age Tutorial with Examples

Today, We want to share with you C# Calculate Age Tutorial with Examples.
In this post we will show you How to Calculate age from Date of Birth in C#, hear for Calculating age from date of birth – C# we will give you demo and example for implement.
In this post, we will learn about C# Calculate age from Date of Birth with an example.

calculate someone’s age in C#

In this post, we will learn about how to calculate someone’s age in C# with an example.

My Paka Knowledgeable Ideas, Tips and Tricks, Useful Content, Jobs, Technology, Earn Money, gmail creation, skype, yahoo and more useful things.

  Amazon S3 File Upload in JavaScript Example

Now in this post, I will explain how to calculate someone’s age in C# with appropriate example.

Now create Console Application in Visual Studio and write below lines of code in it.

using System;
using System.Collections;
using System.Collections.Generic;
namespace PakaInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime _BirthDate = new DateTime(1991, 10, 29);
            DateTime _Now = new DateTime(2017, 12, 23);
            Console.WriteLine(string.Format("Age : {0}", GetAge(_BirthDate, _Now)));
            Console.ReadKey();
        }

        public static int GetAge(DateTime p_BirthDate, DateTime p_Now)
        {
            int age = p_Now.Year - p_BirthDate.Year;

            if (p_Now.Month < p_BirthDate.Month || (p_Now.Month == p_BirthDate.Month && p_Now.Day < p_BirthDate.Day))
                age--;

            return age;
        }
    }
}

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

  WooCommerce Get $product object from product ID

I hope you get an idea about C# Calculate Age Tutorial.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

We hope This Post can help you…….Good Luck!.

Leave a Reply

avatar
  Subscribe  
Notify of