Work out the number of days between two dates

This coding challenge will see you write a C# function to work out the number of days between two dates.

Two dates will be passed in as parameters into the function. The later date will subtract the earlier date and from there, we will return the total number of days between the two dates.

Start off with this function:

public class DateFunctions
	public int DaysLeft(DateTime fromDate, DateTime toDate)

Go ahead and return the number of days between the fromTime and toTime parameter.

Things to consider:

  • The Subtract method in DateTime can be used to subtract two DateTime objects. This methods returns a TimeSpan and the TotalDays property can be used to work out the number of days.
  • The DaysLeft method returns an integer, but the TotalDays property in TimeSpan returns a double. Work out how to convert it to an integer.
  • The number of days returned should not be lower than 0.