DateTime date1 = Convert.ToDateTime('2015/06/20');
DateTime date2= Convert.ToDateTime('2015/05/20');
TimeSpan latetime = date1.Subtract(date2);//here in 'hh:mm:ss' format
string value=latetime.ToString();
I get value as in hh:mm:ss
format.But I want to get it only hh:mm
format
First of all, your code won't even compile. You need to use double quotes for strings, not single quotes.
By the way, what you see (as a format) on
TimeSpan latetime = date1.Subtract(date2);
line is probably just a debugger representation. ATimeSpan
doesn't have any implicit format itself. Formatting concept only will be an issue when you try get it's textual representation.And
TimeSpan
formatting is little bit different thanDateTime
formatting. You can usehh\\:mm
format like;or you can use verbatim string literal;