0

hi
ineed a help in C# programming language i want to know how to a ccount how many Fridays and Saturdays in specific month
can i do it in C#

With Regards,

7
Contributors
10
Replies
11
Views
9 Years
Discussion Span
Last Post by Momerath
0
DateTime tempdate = new DateTime(month you want day 1);
int fridays = 0;
while(tempdate == month you want){
if(tempdate.day = friday){
fridays ++;
}
tempdate.addday();
}

all done, sorry it's in psudeo code

0

I have attached a project that demonstrates how to do this.

Jerry

hi Jerry

i can not open the attached file , what can i use to open that project
please if you can make that project open with visual studio 2005 please do it
and resend it to me

May Thanks

0

Just unzip it and double click FirdayCounter.sln. Visual studio will open it. That appear to be a version 8 file (2005)

0

Yes, I used Visual Studio 2005 to create the project.

It is basically what someone else posted later on:

int Fridays = 0;
            int m_Month = cbMonth.SelectedIndex + 1;
            int m_Year = Convert.ToInt32(edYear.Value);
            DateTime dt = new DateTime(m_Year, m_Month, 1);
            while (dt.Month == m_Month)
            {
                if (dt.DayOfWeek == DayOfWeek.Friday)
                    Fridays++;
                dt = dt.AddDays(1);
            }
            edFridays.Text = Fridays.ToString();

A combobox with all the months (cbMonth), and numericupdown (edYear) and a a simple textbox (edFridays), and ofcourse a Go button that calls the code above.
Basically you need to use the DateTime property (DayOfWeeK0 to determine its day, and increment a counter.

Jerry

0

Yes, I used Visual Studio 2005 to create the project.

It is basically what someone else posted later on:

int Fridays = 0;
            int m_Month = cbMonth.SelectedIndex + 1;
            int m_Year = Convert.ToInt32(edYear.Value);
            DateTime dt = new DateTime(m_Year, m_Month, 1);
            while (dt.Month == m_Month)
            {
                if (dt.DayOfWeek == DayOfWeek.Friday)
                    Fridays++;
                dt = dt.AddDays(1);
            }
            edFridays.Text = Fridays.ToString();

A combobox with all the months (cbMonth), and numericupdown (edYear) and a a simple textbox (edFridays), and ofcourse a Go button that calls the code above.
Basically you need to use the DateTime property (DayOfWeeK0 to determine its day, and increment a counter.

Jerry

Thank you very much Jerry for help

0

Was getting bored with my usaly PM woke, tried quick one hope this helps

DateTime MyDate = DateTime.Now;
MyDate = new DateTime(MyDate.Year, MyDate.Month, 1);
int NoofFridays = 0;
do
{
if (MyDate.DayOfWeek.ToString()   == "Friday")
NoofFridays++;
MyDate = MyDate.AddDays(1);
} w

Edited by happygeek: fixed formatting

0

IT_Techno: hi
ineed a help in C# programming language i want to know how to a ccount how many Fridays and Saturdays in specific month
can i do it in C#

With Regards,

        DateTime MyDate = DateTime.Now;
        MyDate = new DateTime(MyDate.Year, MyDate.Month, 1);
        int NoofFridays = 0;
        do
        {
            if (MyDate.DayOfWeek.ToString()   == "Friday")
                NoofFridays++;
            MyDate = MyDate.AddDays(1);
        } w

Edited by pyTony: fixed formatting

-1

A better algorithm:

public static int NumberOfFridays( int DayOfFirstFridayInMonth, int LengthOfMonth ) {
    int length = LengthOfMonth - DayOfFirstFridayInMonth;
    return ( 1 + ( length / 7 ) );
}

It's better because it's explicit (so it should be faster and it takes less code).

Micah Hoover

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.