C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Find the week for a given date in a month


Posted Date: 07 May 2007    Resource Type: Code Snippets    Category: Date & Time

Posted By: Balamurali Balaji       Member Level: Diamond
Rating:     Points: 10



The following code displays the no. of week in which the given date falls in that month.

In this example code, 23rd of March falls in the 4th week of March of that year.



DateTime userDate = DateTime.Parse("03/23/2007");
int remain;
int noOfWeek;
noOfWeek = Math.DivRem(userDate.Day, 7, out remain);
if (remain > 0)
noOfWeek+=1;
MessageBox.Show(noOfWeek.ToString());





Responses

Author: Rajaraman    12 May 2007Member Level: Diamond   Points : 0
Check this.. It's not working properly.


Author: V i Re N dRa Ku Mar K Oh Li    12 Jun 2007Member Level: Silver   Points : 0
This Code is Not working....


Author: Pendyala    28 Apr 2008Member Level: Gold   Points : 2
This code wil not work...here u hace declared remain...but did not assigned to anything..that is the problem...


Author: andy robarts    28 Apr 2008Member Level: Gold   Points : 2
DateTime userDate = DateTime.Parse("03/23/2007");
int remain=0;
int noOfWeek=0;
noOfWeek = Math.DivRem(userDate.Day, 7, out remain);
if (remain > 0)
noOfWeek+=1;
MessageBox.Show(noOfWeek.ToString());



Author: Balamurali Balaji    03 May 2008Member Level: Diamond   Points : 2
Hello andy, pendyala, vkumar, rajaraman,

Just now today only, I have seen that you all have posted feedback to this code tip.

The code was working correctly in vs2005 with date format (mm/dd/yyyy). When I ran it vs2008, it gave me error in the first line. The correct date format is (dd/mm/yyyy) in vs 2008.
Otherwise, I dont see any error in it. The output is 4.

Kindly bear with the delay in clarifying this.

Goodluck.




Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Get First and Last day of Week from Date
Previous Resource: Display time in a webpage using JavaScript
Return to Discussion Resource Index
Post New Resource
Category: Date & Time


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

silicone halloween mask

Contact Us    Privacy Policy    Terms Of Use