This is the fourth Challenge for this C# course, and it will test your knowledge of the DateTime and TimeSpan data types.

Your Project should be called ChallengeDaysBetweenDates. You will have some simple text at the top of your page that says, "How many days have elapsed?" Your form should include the following Server Controls and Programmatic ID’s:

  1. Calendar1
  2. Calendar2
  3. okButton
  4. resultLabel


The challenge is to allow the user to select a date in the first calendar and another date in the second, then display the number of days between the two:


However, the tricky part is this: If the user selects an earlier date in the second calendar, the displayed result should still only be the number of days between. Think of it as if you were to use integers, but only subtract the smaller value from the larger value. Do this, except with DateTime objects. Once that subtraction is complete, you’ll have a TimeSpan, an from that you’ll want to retrieve the number of days elapsed and display them.

If you need help, review the previous lessons and the Cheat Sheet to refresh your memory on DateTime and TimeSpan types. The solution video is there to help you, but only utilize it if you can’t figure the challenge out on your own. Do your best, and good luck!

Lessons in this Course