I am working with the following code:
static void Main(string[] args)
{
Dates();
Console.ReadLine();
}
public static void Dates()
{
Console.WriteLine("Enter any date: ");
DateTime firstDate = DateTime.Parse(Console.ReadLine());
Console.WriteLine("Enter another date: ");
DateTime secondDate = DateTime.Parse(Console.ReadLine());
TimeSpan diff = firstDate - secondDate;
Console.WriteLine("Days : " + diff.TotalDays.ToString());
Console.WriteLine("Hours : " + diff.TotalHours.ToString());
Console.WriteLine("Minutes : " + diff.TotalMinutes.ToString());
}
I haven't been able to figure out how to calculate the difference in months and years between the two dates. Can anyone help? Also, how can I make the program return a positive integer every time?