how to count how many Fridays in amonth

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 41
Reputation: IT_Techno is an unknown quantity at this point 
Solved Threads: 0
IT_Techno IT_Techno is offline Offline
Light Poster

how to count how many Fridays in amonth

 
0
  #1
Jan 26th, 2008
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,
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: how to count how many Fridays in amonth

 
0
  #2
Jan 26th, 2008
I have attached a project that demonstrates how to do this.

Jerry
Attached Files
File Type: zip FridayCounter.zip (30.6 KB, 11 views)
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 18
Reputation: jonesc5 is an unknown quantity at this point 
Solved Threads: 0
jonesc5 jonesc5 is offline Offline
Newbie Poster

Re: how to count how many Fridays in amonth

 
0
  #3
Jan 26th, 2008
  1. DateTime tempdate = new DateTime(month you want day 1);
  2. int fridays = 0;
  3. while(tempdate == month you want){
  4. if(tempdate.day = friday){
  5. fridays ++;
  6. }
  7. tempdate.addday();
  8. }
all done, sorry it's in psudeo code
Last edited by jonesc5; Jan 26th, 2008 at 12:46 pm. Reason: typo
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 41
Reputation: IT_Techno is an unknown quantity at this point 
Solved Threads: 0
IT_Techno IT_Techno is offline Offline
Light Poster

Re: how to count how many Fridays in amonth

 
0
  #4
Jan 27th, 2008
Originally Posted by JerryShaw View Post
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,614
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 131
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: how to count how many Fridays in amonth

 
0
  #5
Jan 27th, 2008
Just unzip it and double click FirdayCounter.sln. Visual studio will open it. That appear to be a version 8 file (2005)
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: how to count how many Fridays in amonth

 
0
  #6
Jan 28th, 2008
Yes, I used Visual Studio 2005 to create the project.

It is basically what someone else posted later on:

  1. int Fridays = 0;
  2. int m_Month = cbMonth.SelectedIndex + 1;
  3. int m_Year = Convert.ToInt32(edYear.Value);
  4. DateTime dt = new DateTime(m_Year, m_Month, 1);
  5. while (dt.Month == m_Month)
  6. {
  7. if (dt.DayOfWeek == DayOfWeek.Friday)
  8. Fridays++;
  9. dt = dt.AddDays(1);
  10. }
  11. 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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 41
Reputation: IT_Techno is an unknown quantity at this point 
Solved Threads: 0
IT_Techno IT_Techno is offline Offline
Light Poster

Re: how to count how many Fridays in amonth

 
0
  #7
Jan 28th, 2008
Originally Posted by JerryShaw View Post
Yes, I used Visual Studio 2005 to create the project.

It is basically what someone else posted later on:

  1. int Fridays = 0;
  2. int m_Month = cbMonth.SelectedIndex + 1;
  3. int m_Year = Convert.ToInt32(edYear.Value);
  4. DateTime dt = new DateTime(m_Year, m_Month, 1);
  5. while (dt.Month == m_Month)
  6. {
  7. if (dt.DayOfWeek == DayOfWeek.Friday)
  8. Fridays++;
  9. dt = dt.AddDays(1);
  10. }
  11. 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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2
Reputation: youmesh is an unknown quantity at this point 
Solved Threads: 0
youmesh youmesh is offline Offline
Newbie Poster

Re: how to count how many Fridays in amonth

 
0
  #8
Jan 28th, 2008
Originally Posted by IT_Techno View Post
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,
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2
Reputation: youmesh is an unknown quantity at this point 
Solved Threads: 0
youmesh youmesh is offline Offline
Newbie Poster

Re: how to count how many Fridays in amonth

 
0
  #9
Jan 28th, 2008
Originally Posted by IT_Techno View Post
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC