-1

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

2 Answers2

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
0

you can use build in method

DateTime.Parse("12/05/1999 18:25");

you can also check this post

Community
  • 1
  • 1
roy.d
  • 1,030
  • 2
  • 16
  • 33