Date And Time
-
Hi Everybody, Can anyone tell me how we can calculate working hours base on two intervals of time. like Starting Date: 17-05-2006 09:00 AM - Ending Date: 17-05-2006 05:00 PM ? If ending date something like this then what to do? Starting Date: 17-05-2006 09:00 AM - Ending Date: 18-05-2006 08:00 AM I'm using C#.Net |Muhamad Waqas Butt| waqasb4all@yahoo.com www.sktech.freewebspace.com
-
Hi Everybody, Can anyone tell me how we can calculate working hours base on two intervals of time. like Starting Date: 17-05-2006 09:00 AM - Ending Date: 17-05-2006 05:00 PM ? If ending date something like this then what to do? Starting Date: 17-05-2006 09:00 AM - Ending Date: 18-05-2006 08:00 AM I'm using C#.Net |Muhamad Waqas Butt| waqasb4all@yahoo.com www.sktech.freewebspace.com
if you use it as variables of type DateTime then it's not problem. search the commands and static commands between DateTime, and most importent TimeSpan (TimeSpan - Represents Time intervals), I suggest the TimeSpan\DateTime parse method, and TimeSpan.Substract method. if you are still having troubles I'll give you a sample code.
-
Hi Everybody, Can anyone tell me how we can calculate working hours base on two intervals of time. like Starting Date: 17-05-2006 09:00 AM - Ending Date: 17-05-2006 05:00 PM ? If ending date something like this then what to do? Starting Date: 17-05-2006 09:00 AM - Ending Date: 18-05-2006 08:00 AM I'm using C#.Net |Muhamad Waqas Butt| waqasb4all@yahoo.com www.sktech.freewebspace.com
for your request (I got the email... but there is no msg here, so if I would post there you wouldn't get the email notification). I've built this method, a small method that all you need is two datetimes...
private TimeSpan SubTime(DateTime dt1, DateTime dt2) { // Substracts dt1 from dt2 TimeSpan ts = TimeSpan.Parse(dt2.ToString("H:mm:ss")); return ts.Subtract(TimeSpan.Parse(dt1.ToString("H:mm:ss"))); }
now you use it like this:
DateTime dateDiff = DateTime.Parse(SubTime(DateTime.Now, DateTime.Now.AddHours(3)));
simple no? btw I think DateDiff is in SQL... this is C#. if you want to pick datetime you can use the datetimepicker that has alot of functionality, and very comfort, if you want to display the DateTime you just do in a label, Text property = DateTime1.ToString("formatting") eg. DateTime1.ToString("dd-month-yyyy hh:mm AM/PM") // just built it for you from a book I have - needed to custom make some stuff.... should work and if theres a problem try to search it, or if theres a real problem send me a msg... Hope I helped :D NaNg.