syedfaisal

November 27, 2007

Calculating Time Duration For Billing Systems in C#

Filed under: Software Development — Tags: , , , , , , , , , , , , — syedfaisal @ 4:52 pm

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.

Advertisements

4 Comments »

  1. I need your comments on this post: http://stinger.wordpress.com/2007/07/20/n-dimensions/

    Related to maths, philosophy and metaphysics 🙂

    Comment by stinger — November 28, 2007 @ 2:19 am

  2. Great. Thanks for this article. Helped me a bit understanding time spans 🙂

    Comment by Maxi — October 30, 2008 @ 6:43 pm

  3. my pleasure. 😀

    Comment by faisal — October 30, 2008 @ 6:52 pm

  4. well Good enough

    Comment by Sham Ali: — January 13, 2009 @ 4:52 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: