Hi

I am developing an application (using C# and SQL SERVER 2005) for calculating fine in an library.
The fine calculated should not included Sundays.
I have used the following code to calculate the fine.
But the code includes all the sundays and hence Fine is charged for all the sundays.

private void btnFine_Click(object sender, EventArgs e)
    {
            DueDate = Convert.ToDateTime(txtDueDate.Text);
            ReturnedOn = Convert.ToDateTime(dateTimePicker1.Value);

            TimeSpan t = ReturnedOn - DueDate;

            int DelayInReturn = t.Days;

            if (DelayInReturn > 0)
            {
                fine = DelayInReturn * 10;
            }
            MessageBox.Show(Convert.ToString(fine));
}

Can any body help me out in calculating the fine excluding the sundays?

Please help me out!

Thanks in advance!

Edited 3 Years Ago by Reverend Jim: Fixed formatting

Hello s2009,

Hope you are doing well, try this code

//just calculate the total no.of days.
int a = totaldays / 7;
int dayswithoutsundays = totaldays - a;

I hope it will help you.

Hello s2009,

Hope you are doing well, try this code

//just calculate the total no.of days.
int a = totaldays / 7;
int dayswithoutsundays = totaldays - a;

I hope it will help you.

Thanks for your reply.

But still it is counting sundays.

What should I do?

This article has been dead for over six months. Start a new discussion instead.