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.

Read Also:  Laravel 6.2 jQuery AJAX CRUD Tutorial

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.

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.

Read Also:  How to validate mobile number in html? (mobile number validation in html w3schools)

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 :

Read Also:  WooCommerce Get Product Tax, Shipping & Stock

Summary

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

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!.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel 5.6 Data Export to CSV and Excel Example
  2. Read Also:  Laravel Role based permission ACL Tutorial
  3. Read Also:  how to upload project file to github using command line?
  4. Read Also:  KUWAIT UNIVERSITY - Top Universities in Kuwait
  5. Read Also:  PHP Time Ago Function Converting Timestamp
  6. Read Also:  Laravel 6 create zip archive file and download example
  7. Read Also:  whatismyscreenresolution | screen resolution | what is my resolution - Keywords List
  8. Read Also:  Laravel 5.6 Data Export to CSV and Excel Example
  9. Read Also:  whatismyscreenresolution | screen resolution | what is my resolution - Keywords List
  10. Read Also:  WooCommerce Get Product Tax, Shipping & Stock
CLOSEX