Week NumberThis is a featured page



No user avatar
Kauko
Latest page update: made by Kauko , Feb 15 2009, 11:03 AM EST (about this update About This Update Kauko Moved from: OpenInsight Community Source Code - Kauko

No content added or deleted.

- complete history)
Keyword tags: week day week number
More Info: links to this page
Started By Thread Subject Replies Last Post
Kauko Weeknumber routine 0 Feb 15 2009, 11:01 AM EST by Kauko
Thread started: Feb 15 2009, 11:01 AM EST  Watch
compile Function WeekNumber(inDate)

** inDate as MM-DD-YYYY

Declare Function Week_Day, WeekNumber

DayNo = Iconv(inDate,'D4-') - Iconv("01-01-": inDate[7,4],'D4-') + 1

StartDay = Week_Day(Iconv("01-01-": inDate[7,4],'D4-'))
StopDay = Week_Day(Iconv("12-31-": inDate[7,4],'D4-'))

** Number of days belonging to first calendar week
StartDays = 7 - (StartDay - 1)

** Test to see if the year will have 53 weeks or not
If StartDay = 4 Or StopDay = 4 Then ThurFlag = 1 Else ThurFlag = 0
VNumber = Int(((DayNo - StartDays - 4) / 7) + .5)

** If first week has 4 or more days, it will be calendar week 1 If first
** week has less than 4 days,it will belong to last year's last calendar week
If StartDays >= 4 Then
WeekNumber = VNumber + 2
End Else
WeekNumber = VNumber + 1
End

** Handle years whose last days will belong to coming year's first calendar week
If WeekNumber > 52 And ThurFlag = 0 Then WeekNumber = 1

** Handle years whose first days will belong to the last year's last calendar week
If WeekNumber = 0 Then
WeekNumber = WeekNumber("12-31-": inDate[7,4] - 1)
End

Return WeekNumber
*****************************************************************************8
Compile Function Week_Day(tempDate)

Mo = Oconv(tempDate,'D4-')[1,2]
Da = Oconv(tempDate,'D4-')[4,2]
Ce = Oconv(tempDate,'D4-')[7,2]
Yr = Oconv(tempDate,'D4-')[9,2]
Z = Int(2.6 * (Mo - 2 + 1 * 12 * (Mo < 3)) - 0.199)
Z += Da +Yr -1*(Mo < 3) + Int((Yr - 1*(Mo < 3))/4) + Int(Ce / 4) - 2 * Ce
Weekday = (Z-7*Int(Z/7))

Return Weekday
Do you find this valuable?    
Keyword tags: week number
Showing 1 of 1 threads for this page

Related Content

  (what's this?Related ContentThanks to keyword tags, links to related pages and threads are added to the bottom of your pages. Up to 15 links are shown, determined by matching tags and by how recently the content was updated; keeping the most current at the top. Share your feedback on Wetpaint Central.)