Toon posts:

[VBS] Probleempje met week nummers

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hoi

ik heb een probleempje met weeknummers in vbs, namelijk, hij denk volgens mij dat 1jan. op dag 1 van week 1 valt, dit is niet zo, want dat valt in week 53.
dit heeft tot gevolg dat hij de week waar we nu inzitten (12) aangeeft als week 13

ik heb gekeken op

http://www.microsoft.com/.../misc/dates/msdtvb02.mspx
http://www.microsoft.com/...r/guide/sas_vbs_hbev.mspx

en daar staat het volgende
Configuring DatePart Options
By default, VBScript considers the first week of the year to be the week in which January 1 occurs. However, the DatePart function includes an optional parameter that can be used to set the first week of the year to one of the values shown in Table 2.8.

Table 2.8 Parameters for Setting the First Week of the Year

Constant Value Description
vbUseSystem
0
Uses the National Language Support API to determine the first full week based on the regional and language settings.

vbFirstJan1
Sets the first week as the week in which January 1 occurs.

vbFirstFourDays
Sets the first week as the first week to have at least four days in it.

VbFirstFullWeek
Sets the first week as the first week that begins on a Sunday.


To use this parameter, call the DatePart function followed by the "ww" parameter, the date for which the week number is being determined, and the appropriate constant. The following script shows how the different constants can affect the week number assigned to a particular date.

TestDate = "1/6/2003"
Wscript.Echo ProjectedDate
Wscript.Echo "Week of Year: " & DatePart("ww" , TestDate)
Wscript.Echo "Week of Year: " & DatePart("ww" , TestDate, vbFirstJan1)
Wscript.Echo "Week of Year: " & DatePart("ww" , TestDate, vbFirstFourDays)
Wscript.Echo "Week of Year: " & DatePart("ww" , TestDate, vbFirstFullWeek)

When the preceding script runs under CScript, the following output appears in the command window:

1/6/2003
Week of Year: 2
Week of Year: 2
Week of Year: 2
Week of Year: 1

As shown in Figure 2.13, January 6, 2003, does not fall in the same week as January 1, nor does it fall in the first week to have four days. However, it does fall during the first week to start with a Sunday.
maar het lukt mij niet om het goed te krijgen, want bij wat ik getest heb :

code:
1
2
3
4
5
6
TestDate = "24/3/2005"
Wscript.Echo ProjectedDate
Wscript.Echo "Week of Year: " & DatePart("ww" , TestDate)
Wscript.Echo "Week of Year: " & DatePart("ww" , TestDate, vbFirstJan1)
Wscript.Echo "Week of Year: " & DatePart("ww" , TestDate, vbFirstFourDays)
Wscript.Echo "Week of Year: " & DatePart("ww" , TestDate, vbFirstFullWeek)


geeft hij 13 als resultaat,
Wscript.Echo "Week of Year: " & DatePart("ww" , TestDate, vbFirstJan1)
heb ik ook gewijzigt in :
Wscript.Echo "Week of Year: " & DatePart("ww" , TestDate, vbFirstJan3)

maar dit heeft geen effect

grtn Minolta

(hij haald nu de datum weg bij TestDate , dit is tijdelijk, dat word vervangen door Now (nu)

Verwijderd

Topicstarter
volgens mij is het opgelost

Wscript.Echo "Week of Year: " & DatePart("ww" , TestDate, vbMonday ,vbFirstFullWeek)

is de oplossing, want op kalender die ik hier heb start de week op maandag

Minolta
_/-\o_ O-) _/-\o_