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!

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.