Home » C# Calculate Age Tutorial with Examples

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:  Capture Webcam Image with PHP and jQuery

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:  jQuery Accordion Vertical Menu using CSS

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:  Blinking text CSS Animation

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 Global variable Sharing Data with all views
  2. Read Also:  how to Text area Set Max Length And Char Count With JavaScript
  3. Read Also:  Convert and Loop through JSON with PHP and JavaScript Arrays/Objects | json to array php
  4. Read Also:  Laravel jQuery Ajax Upload Multiple Images
  5. Read Also:  Angular 9/8 Material Select Box Examples
  6. Read Also:  PHP Get Folder Path From File Path Examples
  7. Read Also:  Laravel Multiple Database Connections Step By Step
  8. Read Also:  how to Text area Set Max Length And Char Count With JavaScript
  9. Read Also:  Convert and Loop through JSON with PHP and JavaScript Arrays/Objects | json to array php
  10. Read Also:  Laravel jQuery Ajax Upload Multiple Images

Leave a Comment

Your email address will not be published. Required fields are marked *