no of days in a month textbox calendar(what month i choose that days to be displayed) 31
except sundays textbox
(remaining no of days) 26 (this 26 excluded the sundays of what month i choose in the above calendar)
basic salary textbox textbox
2720/31 * 26 2281
similarily i type 2720 divided by what month i choose that day and multiple by excluded the sundays of particular month
and result fetch in to the textbox.
2720 is constant amt
.
Loading
Rahul BhattPosted Jul 10, 2012, 2:13 AM
First you need to take First Date and last Date of selected Month
Using DateTime.DaysInMonth You can get no of Days in Month.
DateTime SDate = Convert.ToDateTime(calDate.Month.ToString() + "/01/" + calDate.Year.ToString());
int DaysInMonth = DateTime.DaysInMonth(cal.SelectedDate.Year, cal.SelectedDate.Month);
DateTime EDate = SDate.AddDays(DaysInMonth - 1);
Now Find No Of Sunday
Int32 SunCnt = 0;
while (SDate.DayOfWeek != DayOfWeek.Sunday)
{
SDate = SDate.AddDays(1);
}
SunCnt = 1;
SDate = SDate.AddDays(7);
while (SDate <= EDate)
{
SunCnt += 1;
SDate = SDate.AddDays(7);
}
Now Exclude sunday from Total no of Days and get your final result
int FinalSalaryDay = DaysInMonth - SunCnt;
Decimal SalaryAmount = 2720;
return ((SalaryAmount / DaysInMonth) * FinalSalaryDay).ToString("#.##");
Full Source Code ::
private string GetFInalSalary()
{
DateTime SDate = Convert.ToDateTime( cal.Month.ToString() + "/01/" + cal.Year.ToString());
int DaysInMonth = DateTime.DaysInMonth(cal.SelectedDate.Year, cal.SelectedDate.Month);
DateTime EDate = SDate.AddDays(DaysInMonth - 1);
Int32 SunCnt = 0;
while (SDate.DayOfWeek != DayOfWeek.Sunday)
{
SDate = SDate.AddDays(1);
}
SunCnt = 1;
SDate = SDate.AddDays(7);
while (SDate <= EDate)
{
SunCnt += 1;
SDate = SDate.AddDays(7);
}
int FinalSalaryDay = DaysInMonth - SunCnt;
Decimal SalaryAmount = 2720;
return ((SalaryAmount / DaysInMonth) * FinalSalaryDay).ToString("#.##");
}
Satyapriya NayakPosted Jul 10, 2012, 1:59 AM
Please Please Please
Don't create duplicate thread.
http://www.c-sharpcorner.com/Forums/Thread/178614/amount-calculate.aspx
Thanks