I have string with datetime format dd/MM/yyyy hh:mm.I want to calculate duration between two dates but failed to get datetime in correct format.please help. thanks in advance
Asked
Active
Viewed 1,753 times
-1
-
4Could you please show your work and where you stuck. – Soner Gönül May 22 '14 at 06:49
-
7You say you've "failed" - that suggests you've tried something already. Please show what you've tried and explain what happened. – Jon Skeet May 22 '14 at 06:52
2 Answers
0
After parsing date string create two dates.
DateTime date1 = new DateTime();
DateTime date2 = new DateTime();
date1 = DateTime.Parse("22/05/2013 09:50:00");
date2 = DateTime.Parse("22/05/2014 09:50:00");
Then use TimeSpan structure to calculate interval:
TimeSpan ts_interval = date2 - date1;
You can use the following properties:
ts_interval.TotalSeconds;
ts_interval.TotalMinutes;
ts_interval.TotalHours;
For more visit http://msdn.microsoft.com/en-us/library/system.timespan_properties%28v=vs.110%29.aspx

zkanoca
- 9,664
- 9
- 50
- 94