ISCL is a Intelligent Information Consulting System. Based on our knowledgebase, using AI tools such as CHATGPT, Customers could customize the information according to their needs, So as to achieve

How to Find the Date Difference in C#

2
    • 1). Define the first DateTime object. For example, you can store a value for midnight on August 20, 2000, with the line "System.DateTime timeOne = new System.DateTime(2000,8,20,0,0,0);" without quotes. The first parameter is the year, the second the month, the third the day, the fourth the hour, the fifth the minute and the sixth the second. Consult the MSDN DateTime documentation for more options.

    • 2). Define the second DateTime object. For example, we can set it to July 20, 2010, with the line: "System.DateTime timeTwo = new System.DateTime(2010,7,20,0,0,0);".

    • 3). Invoke the Subtract method within the DateTime object, storing the most recent value, and save the result in a new TimeSpan value. We can subtract from our previous sample with the command: "System.TimeSpan diffStore = timeTwo.Subtract(timeOne);".

    • 4). Use the "Days" value within the TimeSpan inside your application. You can display it using: "Console.WriteLine(diffStore.Days);".

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.