programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Monday, December 16, 2013

How to Calculate Number of Sunday in a particular month by programming

How to Calculate Number of Sunday in a particular month by programming:

When we make Pay roll type system the and many other time where we want to get the number of Sunday (how many time a particular day come in a particular month);
For this we create a particular function in C# programming Language .i think it is use full for you.  

private int GetOccuranceOfWeekday(int Year, int Month, DayOfWeek Weekday)
        int ReturnValue = 0;
        DateTime MyDate = new DateTime(Year, Month, 1);
        int Start = 1;
        if (Weekday != MyDate.DayOfWeek)
            Start = -(MyDate.DayOfWeek - Weekday - 1);
            if (Start <= 0)
                ReturnValue = -1;

        while (Start <= DateTime.DaysInMonth(Year, Month))
            ReturnValue += 1;
            Start += 7;
        return ReturnValue;

The name of this function is ‘GetOccuranceOfWeekday’ as you see this function take 3 variables as a argument and return a particulate value.

How to this Function:
We can call this function as like this ……..

Label1.Text=(GetOccuranceOfWeekday(2013, 10, DayOfWeek.Sunday)).ToString();

Code of  .Aspx page :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="numberodsundayin_month.aspx.cs" Inherits="numberodsundayin_month" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

Other Related Post: