Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a code in which i want to subract 19-06-2014 00:01:13 with 18-06-2014 23:58:13 to get 3 minutes as difference but currently i am getting -23:57:00.I am using timespan and timeofday to get the time only from this date.
Posted
Comments
Richard MacCutchan 19-Jun-14 12:20pm    
Use the DateTime type for your two values then the TimeSpan calculation will take the date portions into account.

I'm trying to recreate your problem.
C#
DateTime dt1 =DateTime.ParseExact("19-06-2014 00:01:13", "dd-MM-yyyy HH:mm:ss",null);
DateTime dt2 =DateTime.ParseExact("18-06-2014 23:58:13", "dd-MM-yyyy HH:mm:ss",null);

with above two DateTime objects,
C#
var minutes = (dt1-dt2).TotalMinutes; // result is 3. 
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Jun-14 21:02pm    
Correct, a 5.
—SA
DamithSL 19-Jun-14 22:01pm    
Thank you SA
agent_kruger 20-Jun-14 0:00am    
+5 very simple solution
DamithSL 20-Jun-14 0:01am    
Thank you Agent_Spock
agent_kruger 20-Jun-14 0:02am    
you're welocme
SELECT DATEDIFF(MINUTE,'2014-06-18 23:58:13','2014-06-19 00:01:13') AS MinuteDiff
 
Share this answer
 
Comments
ArunRajendra 20-Jun-14 0:39am    
Requirement is in C# not in SQL.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900