hi,
i have year calender. i want to count the days in a year. when i am select year in a dropdown i want to display the days count of that year.
and aslo i have to display the days count exclude sunday of the whole year.
pls help me.
its urjent, post code or give some demos link
Loading
VulpesPosted Aug 3, 2012, 6:17 AM
Jignesh TrivediPosted Aug 3, 2012, 3:50 AM
try....
private static int GetDaysInAYearWithoutSunday(int year)
{
int days = 0;
for (int i = 1; i <= 12; i++)
{
int sundaycount = GetNumberOfSundays(i, year);
days = days += sundaycount;
}
return days;
}
private static int GetNumberOfSundays(Int32 Month, Int32 Year)
{
DateTime StartDate = new DateTime(Year, Month, 1);
Int32 iDays = DateTime.DaysInMonth(Year, Month);
DateTime EndDate = StartDate.AddDays(iDays - 1);
Int32 SundayCount = 0;
while (StartDate.DayOfWeek != DayOfWeek.Sunday)
{
StartDate = StartDate.AddDays(1);
}
SundayCount = 1;
StartDate = StartDate.AddDays(7);
while (StartDate <= EndDate)
{
SundayCount += 1; StartDate = StartDate.AddDays(7);
}
return iDays - SundayCount;
}
static void Main(string[] args)
{
int vvv = GetDaysInAYearWithoutSunday(2012);
}
hope this will help you.
Farooque AliPosted Aug 3, 2012, 2:56 AM
http://www.dbforums.com/mysql/981086-count-days-excluding-weekends.html
Sachin KaliaPosted Aug 3, 2012, 2:54 AM
Please go through the link below.
http://www.c-sharpcorner.com/Blogs/4202/
also the code snippet from the above link.
private int GetDaysInAYear(int year)
{
int days = 0;
for (int i = 1; i <= 12; i++)
{
days += DateTime.DaysInMonth(year, i);
}
return days;
}
Kindly pass the dropdown value as an parameter as year.
Hope this make you happy.
Cheers .Net
Sachin KaliaPosted Aug 3, 2012, 2:54 AM
Please go through the link below.
http://www.c-sharpcorner.com/Blogs/4202/
also the code snippet from the above link.
private int GetDaysInAYear(int year)
{
int days = 0;
for (int i = 1; i <= 12; i++)
{
days += DateTime.DaysInMonth(year, i);
}
return days;
}
Kindly pass teh dropdownvalue as an parameter as year.
Hope this make you happy.
Cheers .Net