DateTime date1 = System.Convert.ToDateTime(DTimeBeginWork.Value);
DateTime date2 = System.Convert.ToDateTime(DTimeEndWork.Value);
string date1String = date1.ToString("dd-MM-yyyy hh:mm:ss tt");
string date2String = date2.ToString("dd-MM-yyyy hh:mm:ss tt");
TimeSpan ts = new TimeSpan();
ts = date2.Subtract(date1);
DgNHours.DigitText = (ts.TotalHours.ToString());
DgNMinutes.DigitText = (ts.Minutes.ToString());
In your code I added two statements for displaying date1 and date2 also changed the ts.Hours to ts.TotalHours. As per your example if you pass (11:00 PM to 1:00 AM) this code will return -22.
That is correct because if you check date1String and date2String it will be 03-07-2013 11:00:00 PM
and 03-07-2013 01:00:00 AM respectively ( as per today's date), the difference between these date will be -22.
If you pass the values as 03-07-2013 11:00:00 PM to 04-07-2013 01:00:00 AM then it will return 2 as result.So you have to pass the date along with the time value to get the proper result.