19. februar 2004 - 11:20Der er
2 kommentarer og 2 løsninger
Uge numre igen igen
Jeg har lige et sjovt spørgsmål angående ugenumre Jeg bruger funktionen Format(datDato, "ww", vbMonday, vbFirstFourDays) til at finde ugenumre med. Hvis man tester med 28-12-2003 får som forventet uge 52 Hvis man tester med 29-12-2003 får man mod forventning uge 53 Hvis man tester med 30-12-2003 får man som forventet uge 1
'******************************************************* ' Translates the date passed into a week number '******************************************************* Function WEEK_NUM(p_Date As String) On Error Resume Next If Not IsDate(p_Date) Then Exit Function
'This is difference between the sent date and the first date of ' the first week in the year ' (plus one since the first week is 1 and not 0) WEEK_NUM = Fix((CDate(p_Date) - CDate(FIRST_UGE(p_Date))) / 7) + 1
End Function '******************************************************* ' This tells you what day the first week in the year starts on '******************************************************* Function FIRST_UGE(p_Date As String) On Error Resume Next
Dim fYear As Integer Dim f_WeekDay As Integer
'What day of the week was the first day of the passed year fYear = Year(p_Date) f_WeekDay = WeekDay("1-1-" & fYear, vbMonday) If 7 - f_WeekDay >= 3 Then 'week 1 starts before the first FIRST_UGE = CVDate("1-1-" & fYear) - (f_WeekDay - 1) Else 'week 1 starts after the first FIRST_UGE = CVDate("1-1-" & fYear) + (8 - f_WeekDay) End If
End Function
So you would only type WEEK_NUM(datDato) to get the week number. Yes it's bizzare but heh...Det virke!
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.