Calculate the difference between two dates in c #, to get the number of days
This simple example allows you to calculate the number of days that passed between two dates.
Code:
using System;
namespace ConsoleApplications
{
class DateDemo
{
static void Main(string[] args)
{
// Insert date of birth, or anothore old day
DateTime dateOfBirth = new DateTime(1982, 8, 24);
// The current date, or insert another day
DateTime today = DateTime.Now;
TimeSpan ts = today - dateOfBirth;
int days = ts.Days;
System.Console.WriteLine("You lived {0} beautiful days! ", days);
}
}
}