How to find date difference in C#

Jak
Jak
Member
352 Points
151 Posts

Hi,

How to find date difference in C#?

I want to create timer on the basis of start and end date stored in database. I want to calculate time difference in the format HH:mm:ss in asp.net c#.

But unable to find the difference.

Views: 8158
Total Answered: 1
Total Marked As Answer: 0
Posted On: 30-Sep-2015 03:28

Share:   fb twitter linkedin
Answers
Smith
Smith
Participant
360 Points
110 Posts
     

Hi Jak,

You need to use TimeSpan in C# to calculate date differece as: 

TimeSpan TempSpan; 
DateTime DateTime1=new DateTime("2015/10/11"); 
DateTime DateTime2=new DateTime("2015/11/11");
TempSpan = DateTime2 - DateTime1; 
 
int Days = TempSpan.Days; 
int Hours = TempSpan.Hours; 
int Minute = TempSpan.Minutes; 
int Second = TempSpan.Seconds; 
string Datediff = Days + " days, " + Hours + " hours, " + Minute + " minutes, " + Second + " seconds ";
 
string Datediff1 = TempSpan.TotalMinutes + " minutes";

 where Datediff gives the date difference in days, hour, minute, and seconds and Datediff1 gives date difference in seconds.

Posted On: 27-Nov-2015 08:40
banner

Blog

Active User (2)

 Log In to Chat