08. august 2001 - 19:42Der er
10 kommentarer og 1 løsning
Har brug for hjælp til at konverterer et tal til et årstal+måned+dato
Jeg har et mindre problem, som jeg skal have køst og helst inden 22 iaften (08.08.2001). jeg har en Access2000 DB hvor posterne er oprette efter vores lokale system, hvor lotnr består af årstal uge og dag(eks. 2000401) for mandag i uge 40, nu skal jeg have dette konverteret til datoen for denne dag + alle andre poster.
Function YYYYWW2Date(ByVal varYear As Integer, ByVal varWeekNo As Integer) As Date
Function complies with DS/EN 28601. \' Monday is always the first day of the week (also if its in previos year). \' Week 1 is the first week of the year containing at least four days and will always contain \' the first Thirsday of the year.
\' This function also assumes that the WW part is the week which commences in the YYYY part. \' This is because some years have the same week number twice, for example week 52 in year 2000.
Dim v As Variant Dim varMonday As Variant
\'Find first manday of year varMonday = DateSerial(varYear, 1, 1) \'first day of year While WeekDay(varMonday) <> 2 \'weekday() has monday as day 2 of week varMonday = DateAdd(\"d\", 1, varMonday) \'add a day until we have the first monday Wend
\'Returns date v = DateSerial(varYear, 1, (varWeekNo - 1) * 7 + Day(varMonday)) \'v er her søndagen i den pågældende uge
\'If the first Monday of the year is in week we need to subtract a week. (EG:2002) varWeekNo = val(Format$(varMonday, \"ww\", vbMonday, vbFirstFourDays)) If varWeekNo = 2 Then v = DateAdd(\"d\", -7, v) End If
YYYYWW2Date = v
End Function
I dont know how you are going to update the field but you can use this to convert the year and weeknumber to a date which will always be a monday, then the DateAdd adds the day to get to the correct day of the week..
I havent checked this call but its soemthing like this
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.