
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to get the difference between two dates in seconds
Set two dates.
DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 7, 15, 11, 14, 25);
Now calculate the difference between two dates.
TimeSpan ts = date2 - date1;
Move further and calculate the difference in seconds.
ts.TotalSeconds
Let us see the complete code.
Example
using System; using System.Linq; public class Demo { public static void Main() { DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 7, 15, 11, 14, 25); TimeSpan ts = date2 - date1; Console.WriteLine("No. of Seconds (Difference) = {0}", ts.TotalSeconds); } }
Output
No. of Seconds (Difference) = 10745
- Related Questions & Answers
- C# Program to get the difference between two dates
- How to get the number of seconds between two Dates in JavaScript?
- Java Program to get the difference between two time zones by seconds
- How to get the difference between two dates in Android?
- C# Program to determine the difference in hours between two dates
- Get the difference between two timestamps in seconds in MySQL?
- Not able to get the difference between two dates (SAP)
- How to get time difference between two timestamps in seconds?
- MySQL difference between two timestamps in Seconds?
- How to calculate the difference between two dates in JavaScript?
- How to get the differences between two dates in iOS?
- Difference between two timestamps in seconds in MySQL?
- Java Program to get milliseconds between dates
- How to get the number of days between two Dates in JavaScript?
- How to get the differences between two dates in Android using Kotlin?
Advertisements