I’m trying to use c# to get the number of days in-between two dates.
Here is my little program:
public class Program
{
public static void Main()
{
DateTime today = DateTime.Now;
DateTime futureDate = DateTime.Today.AddDays(3);
int daysBetween = (int)Math.Round((futureDate - today).TotalDays);
Console.WriteLine("Date testing\n\n");
Console.WriteLine("Today: {0:MM/dd/yy H:mm}", today);
Console.WriteLine("futureDate: {0:MM/dd/yy H:mm}", futureDate);
Console.WriteLine("daysBetween: ", daysBetween);
}
}
This is what I am getting.
Date testing
Today: 04/01/22 14:10
futureDate: 04/04/22 0:00
dateNumber:
For some reason, dateNumber is blank, but I am expecting it to be 3.
Is there a way to get that number?
Thanks!
>Solution :
You are printing a formatted string. The {0} means to insert the first parameter following the format string;
Console.WriteLine("daysBetween: {0} ", daysBetween);