Hi
I tried Age calculator ...Only Displaying The Year ... I am getting exact the output of Months and Days ..I need Months Caluclation and Days Caluclation.
Please Send me Any one Help me ............
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Santosh Ubale35 reputationPosted Aug 7, 2014, 5:56 AM EDT
This might help you
link: Calculate Age (Years + Months + Days) in C#
Thanks :)
"LIKE THIS ANSWER IF IT HELPS YOU" :)
Staff uniquewebdevelopers4 reputationPosted Sep 22, 2025, 1:52 PM EDT
You can calculate age in Years, Months, and Days by comparing the birth date with today’s date. The logic is:
Subtract the birth year from the current year for the years.
If today’s month is less than the birth month, subtract 1 year and adjust the months.
Do the same for days if today’s day is less than the birth day, borrow days from the previous month.
Example:
Birthdate:
2000-05-10Today:
2025-09-22Result → 25 Years, 4 Months, 12 Days
Most programming languages (like PHP, JavaScript, or Python) have built-in date functions to handle this calculation easily.
If you’d like to try it online, here’s a simple tool that does the calculation: Age Calculator
Sandhiya PriyaRank #26 · 43.2K reputationPosted Oct 23, 2025, 12:04 AM EDT
You’re trying to build an Age Calculator (in C# or JavaScript?), and right now it’s only showing years, but you also want months and days to be calculated accurately.
Let’s cover both cases — C# (backend) and JavaScript (frontend) — since many people do this in either.
Option 1: C# — Accurate Age in Years, Months, and Days
Here’s a clean method that gives exact years, months, and days between two dates:
using System; public class Program { public static void Main() { Console.Write("Enter your birthdate (yyyy-mm-dd): "); DateTime birthDate = DateTime.Parse(Console.ReadLine()); DateTime today = DateTime.Today; int years = today.Year - birthDate.Year; int months = today.Month - birthDate.Month; int days = today.Day - birthDate.Day; // Adjust if current month/day is before birth month/day if (days < 0) { months--; DateTime prevMonth = today.AddMonths(-1); days += DateTime.DaysInMonth(prevMonth.Year, prevMonth.Month); } if (months < 0) { years--; months += 12; } Console.WriteLine($"Age: {years} years, {months} months, {days} days"); } }Example Output
If today is 2025-10-23 and birthdate is 2000-05-10,
it will print:
Option 2: JavaScript (Web UI version)
If your age calculator runs in a web page:
Age Calculator Age Calculator Calculate function calculateAge() { const dob = new Date(document.getElementById("dob").value); const today = new Date(); let years = today.getFullYear() - dob.getFullYear(); let months = today.getMonth() - dob.getMonth(); let days = today.getDate() - dob.getDate(); if (daysExample Output
Explanation
We first subtract years, months, and days separately.
If
days < 0, it means the current day hasn’t reached the birth day yet in this month,so we borrow days from the previous month.
If
months < 0, it means the current month hasn’t reached the birth month,so we borrow one year and add 12 months.