C#: Difference between two dates in days
C# Sharp DateTime: Exercise-30 with Solution
Write a C# Sharp program to get the difference between two dates in days.
Sample Solution:-
C# Sharp Code:
using System;
class Example30
{
public static void Main()
{
//establish DateTimes
DateTime start = new DateTime(2010, 6, 14);
DateTime end = new DateTime(2016, 08, 14);
TimeSpan difference = end - start; //create TimeSpan object
Console.WriteLine("Difference in days: " + difference.Days); //Extract days, write to Console.
}
}
Sample Output:
Difference in days: 2253
Flowchart:

C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# Sharp program to convert the specified string representation of a date and time to its DateTime equivalent using the specified array of formats, culture-specific format information, and style.
Next: Write a C# Sharp program to convert the value of the current DateTime object to local time.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook