To get sundays in a month

Posted by Amritha444 under C# on 11/11/2010 | Points: 10 | Views : 4248 | Status : [Member] | Replies : 3
I want a function to return no sundays in a month.Can anybody suggest good methods




Responses

Posted by: Laghaterohan on: 11/11/2010 [Member] Starter | Points: 25

Up
0
Down
Hi Amritha,

You can use Javascript to find sunday in month and give appropirate alert if sunday is selected by the user.

function checkDay(txtDate) {

if(document.getElementById(txtDate).value.replace('/','').length>0)
{
var checkSunday = document.getElementById(txtDate).value.split('/');
var selectedDate = checkSunday[0];
var selectedMonth = checkSunday[1];
var selectedYear = checkSunday[2].substring(0, 4);
var calendarDate = new Date(selectedYear, selectedMonth - 1, selectedDate);

if (calendarDate.getDay() == 0) {
var r = confirm("Selected date is Sunday! Do you want to continue?");
if (r == false) {
document.getElementById(txtDate).value = "";
}
}
}
}


Best Regards,
Rohan Laghate

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 11/11/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Amritha,

Same question also discuss in the following link...

http://www.dotnetspark.com/kb/1950-code-to-find-number-sunday-for-given-month.aspx

Cheers :)

Thanks,
T.Saravanan

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 11/11/2010 [Member] Bronze | Points: 25

Up
0
Down
Here sample code
private int NumMondays(string month_name, string year_name) 

{
int i;
int num_mondays;
System.DateTime test_date;
int orig_month;
test_date = System.Convert.ToDateTime(month_name + " 1, " + year_name);
if (Weekday(test_date) == vbMonday) {
} else if (Weekday(test_date) == vbTuesday) {
test_date = DateAdd("d", 6, test_date);
} else if (Weekday(test_date) == vbWednesday) {
test_date = DateAdd("d", 5, test_date);
} else if (Weekday(test_date) == vbThursday) {
test_date = DateAdd("d", 4, test_date);
} else if (Weekday(test_date) == vbFriday) {
test_date = DateAdd("d", 3, test_date);
} else if (Weekday(test_date) == vbSaturday) {
test_date = DateAdd("d", 2, test_date);
} else if (Weekday(test_date) == vbSunday) {
test_date = DateAdd("d", 1, test_date);
}
orig_month = Month(test_date);
do {
num_mondays = num_mondays + 1;
test_date = DateAdd("ww", 1, test_date);
} while ((Month(test_date) == orig_month));
NumMondays = num_mondays;
}


show this good article Get all Sunday in a Year
http://www.dotnetspider.com/resources/27488-Get-all-Sunday-Year.aspx

LP MER

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response