.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 22nd, 2005, 09:38 PM
dennisau dennisau is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 4 dennisau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 48 sec
Reputation Power: 0
Unhappy Week In Month

I have a problem , which I got a date and I need to know that this date is what week for that month ? Like week1 , week2 , week3....
HOw can I do it in vb.net ??

Thanks you !!

Reply With Quote
  #2  
Old February 23rd, 2005, 05:21 AM
voltaire voltaire is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 voltaire User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 53 sec
Reputation Power: 0
DateTime has a property called DayOfYear which you could divide by 7.
Dont forget to consider the cases where the year does not begin neatly on the first day of the week

Reply With Quote
  #3  
Old February 27th, 2005, 07:00 PM
dennisau dennisau is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 4 dennisau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 48 sec
Reputation Power: 0
thanks for your advise.. I got the solution already ~~!!

Reply With Quote
  #4  
Old March 1st, 2005, 10:31 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Dennisau:
I'm curious, what was the solution you used?

Reply With Quote
  #5  
Old March 10th, 2005, 05:16 AM
dennisau dennisau is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 4 dennisau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 48 sec
Reputation Power: 0
Wink

Below here the code for the solution... If anybody like can try for it ~~!!!


Public
Function GetWeekOfMonth(ByVal xYear AsInteger, ByVal xMonth AsInteger, ByVal xDay AsInteger) AsInteger
Try

Dim xDate AsDate
Dim xDate1 As DayOfWeek
Dim xFirstdayOfMonth AsInteger
Dim xWeek1DayRange AsString
Dim xWeek2DayRange AsString
Dim xWeek3DayRange AsString
Dim xWeek4DayRange AsString
Dim xWeek5DayRange AsString
Dim xWeek1() AsString
Dim xWeek2() AsString
Dim xWeek3() AsString
Dim xWeek4() AsString
Dim xWeek5() AsString
Dim xMaxDay() AsInteger = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0}
Dim xTotalDayOfMonth AsInteger
xDate = DateSerial(xYear, xMonth, 1)

xTotalDayOfMonth = xMaxDay(xMonth)

If xMonth = 2 Then

If ((xYear Mod 4 = 0 And xYear Mod 100 <> 0) Or xYear Mod 400 = 0) Then

xTotalDayOfMonth = xTotalDayOfMonth + 1

EndIf

EndIf

xDate1 = xDate.DayOfWeek

xFirstdayOfMonth = xDate1

xWeek1DayRange = 1 & "," & 7 - xFirstdayOfMonth

xWeek2DayRange = 7 - xFirstdayOfMonth + 1 & "," & 7 - xFirstdayOfMonth + 1 + 6

xWeek3DayRange = 7 - xFirstdayOfMonth + 1 + 6 + 1 & "," & 7 - xFirstdayOfMonth + 1 + 6 + 6 + 1

xWeek4DayRange = 7 - xFirstdayOfMonth + 1 + 6 + 6 + 1 + 1 & "," & 7 - xFirstdayOfMonth + 1 + 6 + 6 + 6 + 1 + 1

xWeek5DayRange = 7 - xFirstdayOfMonth + 1 + 6 + 6 + 6 + 1 + 1 + 1 & "," & xTotalDayOfMonth

xWeek1 = xWeek1DayRange.Split(",".ToCharArray)

xWeek2 = xWeek2DayRange.Split(",".ToCharArray)

xWeek3 = xWeek3DayRange.Split(",".ToCharArray)

xWeek4 = xWeek4DayRange.Split(",".ToCharArray)

xWeek5 = xWeek5DayRange.Split(",".ToCharArray)



If xDay < xWeek1(1) Then

GetWeekOfMonth = 1

Else

If xDay > xWeek2(1) Then

If xDay > xWeek3(1) Then

If xDay > xWeek4(1) Then

GetWeekOfMonth = 5

Else

GetWeekOfMonth = 4

EndIf

Else

GetWeekOfMonth = 3

EndIf

Else

GetWeekOfMonth = 2

EndIf

EndIf

Catch errMsg As System.Exception

mdlMsg.Msg("ClassSystem.GetWeekOfMonth : " & errMsg.Message, mdlMsg.MessageType.ErrorMsg)

GetWeekOfMonth = 0

EndTry

EndFunction



Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > Week In Month


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT