If you are developing a hotel management system, car parking area management system etc then you will need to calculate the charges per hour,min etc.
Below is the code I used in my application for per hour billing with a condition that after 10 minutes of every new hour it charges for full hour:
DateTime c = DateTime.Parse(“11/27/2007 11:59:43 PM”);
//ref time you can use entry time etc
DateTime endTime = DateTime.Now;
TimeSpan span = endTime.Subtract(c);
TimeSpan span2 = span.Duration();
string Shours= span2.Hours.ToString();
string Smin = span2.Minutes.ToString();
int Imin = int.Parse(Smin);
int Ihours = int.Parse(Shours);
if (Imin > 10)
{
Ihours = Ihours + 1; }
int charges=Ihours*100;
Label1.Text = “Hours Used:”+Ihours.ToString()+“,Charges@100 Rs perhour:”+charges.ToString() ;
The output will be in the form of:
Hours Used:17,Charges@100 Rs perhour:1700 (obviously this is the output I got wrt my system time)
I hope the code will help you in your application development.


