hiiii
My web application is of Payroll System
Question: I have to check how many Leaves employee has taken, but organization has 1st and 3rd and in some cases 5th Saturday working. Now my question is if employee has taken leave on First Saturday then that should also count. But I m unable to check how to check that perticular saturday is 1st, 3rd, or 5th.....
Currently I'm able to find Saturdays and Sundays from Number of leaves but unable to find 1st,3rd,5th saturday...
plz reply
thx in advance
Loading
Amruta KirdatPosted May 27, 2011, 6:36 AM
i did something like this.... n its working
for (DateTime dtLFrom = dtLeaveFrom; dtLFrom <= dtLeaveTo; dtLFrom = dtLFrom.AddDays(1))
{
DayOfWeek d = dtLFrom.DayOfWeek;
string strDay = Convert.ToString(d.ToString());
if (strDay == "Saturday" || strDay == "Sunday")
{
if (strDay == "Saturday")
{
int intYear = dtLFrom.Year;
int intMonth = dtLFrom.Month;
int intLastDayOfMonth = System.DateTime.DaysInMonth(intYear, intMonth);
string strLastDayOfMonth = intMonth + "/" + intLastDayOfMonth + "/" + intYear;
string strFirstDayOfMonth = intMonth + "/" + 1 + "/" + intYear;
DateTime dtLastDayOfMonth = Convert.ToDateTime(strLastDayOfMonth);
DateTime dtFirstDayOfMonth = Convert.ToDateTime(strFirstDayOfMonth);
for (DateTime dtLast = dtLastDayOfMonth; dtFirstDayOfMonth <= dtLast; dtFirstDayOfMonth = dtFirstDayOfMonth.AddDays(1) )
{
DayOfWeek dowFirst = dtFirstDayOfMonth.DayOfWeek;
string strDayFirst = Convert.ToString(dowFirst.ToString());
if (strDayFirst == "Saturday")
{
DateTime dtAllSaturdays = dtFirstDayOfMonth;
arrAllSaturdays.Add(Convert.ToString(dtAllSaturdays));
}
}
}
intdays = intdays - 1;
}
}
int intIndex = 0;
int c = 0;
if (arrAllSaturdays.Count > 0)
{
for (; c < arrAllSaturdays.Count; c++)
{
intIndex = c;
}
arrSaturdays.Add(arrAllSaturdays[0]);
arrSaturdays.Add(arrAllSaturdays[2]);
if (intIndex == 4)
{
arrSaturdays.Add(arrAllSaturdays[4]);
}
}
VulpesPosted May 27, 2011, 4:53 AM
Bryian TanPosted May 27, 2011, 1:39 AM
I did something like that before. We have to display a banner on the website on Saturday, it can be 1st, 2nd, 3rd, 4th, 5th of the month. Check it out.
http://blog.ysatech.com/post/2009/06/27/How-to-get-the-date-of-a-day-of-a-given-week-number-in-a-month.aspx