Monday, 30 December 2013

How to Get the Difference between the Two Days

In this post we can see how to get the difference between the two dates
DateTime dt1 = DateTime.Now;
            DateTime dt2 = DateTime.Now.AddDays(3).AddSeconds(34);
            TimeSpan span = dt2 - dt1;
            Console.WriteLine(" Days: " + span.Days +" Min: "+span.Minutes+" Sec: "+span.Seconds);


Days: 3 Min: 0 Sec: 34

Add the Span to the Date:

DateTime Sample = DateTime.Now.AddDays(4);

From this post you can learn how to add the date and difference between the dates.

No comments:

Post a Comment