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,

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

Jerry

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

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

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

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

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

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

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

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

Thread is 4 years old! Don't reply to 4 year old threads.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.