C#

Calculate Month years and days between two dates in c #

Here is an example to calculate dates difference in c# class Program { static void Main(string[] args) { DateTime zeroTime = new DateTime(1, 1, 1); DateTime olddate = DateTime.Today; DateTime curdate = new DateTime(2023, 1, 29); TimeSpan span = curdate - olddate; int years = (zeroTime + span).Year - 1; int months = (zeroTime + span).Month - 1; int days = (zeroTime + span).Day-1; var totalMonth =Convert.ToDouble((years * 12 + months)+"."+days); } }