Time Subtract
-
Hi Respected Seniors, Kindly let me know one or two examples, How may I subtract / "Diffrence" time. for example: string strStudentTime = "10:00"; string strSystemTime = "10:15"; I need difference. Thank you (Riaz Bashir)
-
Hi Respected Seniors, Kindly let me know one or two examples, How may I subtract / "Diffrence" time. for example: string strStudentTime = "10:00"; string strSystemTime = "10:15"; I need difference. Thank you (Riaz Bashir)
-
Hi Respected Seniors, Kindly let me know one or two examples, How may I subtract / "Diffrence" time. for example: string strStudentTime = "10:00"; string strSystemTime = "10:15"; I need difference. Thank you (Riaz Bashir)
As Hiren said, look at the TimeSpan class. Specifically, you'll need to read these values in (using TryParse) to a TimeSpan, and then you can get the difference from there.
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
-
Hi Respected Seniors, Kindly let me know one or two examples, How may I subtract / "Diffrence" time. for example: string strStudentTime = "10:00"; string strSystemTime = "10:15"; I need difference. Thank you (Riaz Bashir)
You should not hold times, dates, or datetimes in strings; strings here are useful only for showing actual values to human users. Keep them in DateTime types instead, so you have all DateTime operators and methods available, including subtraction, which results in a TimeSpan. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Hi Respected Seniors, Kindly let me know one or two examples, How may I subtract / "Diffrence" time. for example: string strStudentTime = "10:00"; string strSystemTime = "10:15"; I need difference. Thank you (Riaz Bashir)
If it is a 24-hour clock, and the format is fixed as hh:mm, you can do it in a very simple way, without the system classes:
private static int ParseTime(string s) {
return 60*int.Parse(s.Substring(0, 2)) + int.Parse(s.Substring(3));
}
...
var diffInMinutes = ParseTime(strSystemTime) - ParseTime(strSystemTime);If your code needs to be more robust than that, you should use DateTime to parse your strings, and then use the "-" operator to obtain their difference.
-
Hi Respected Seniors, Kindly let me know one or two examples, How may I subtract / "Diffrence" time. for example: string strStudentTime = "10:00"; string strSystemTime = "10:15"; I need difference. Thank you (Riaz Bashir)