(view source code of week.vbs as plain text)
Option ExplicitDim intWeek, wshShell, wshUserEnv' Check command line argument(s)If WScript.Arguments.Named.Count > 0 Then Syntax
With WScript.Arguments.Unnamed
If .Count = 1 Then
' Check if valid date is specified on the command lineIf IsDate( .Item(0) ) Then
intWeek = DatePart( "ww", .Item(0), vbMonday, vbFirstFourDays )
ElseSyntax
End If
ElseIf .Count = 0 Then
' Calculate today's week number if no date was specifiedintWeek = DatePart( "ww", Date, vbMonday, vbFirstFourDays )
ElseSyntax
End If
End With
' Set the result in an environment variable "Week"Set wshShell = CreateObject( "WScript.Shell" )
Set wshUserEnv = wshShell.Environment( "USER" )
wshUserEnv( "Week" ) = intWeek
Set wshUserEnv = Nothing
Set wshShell = Nothing
' Display the resultWScript.Echo intWeek
' Exit with the resulting week number as return codeWScript.Quit intWeek
Sub SyntaxWScript.Echo "Week.vbs, Version 2.00 for Windows Script Host 2.00" _
& vbCrLf _& "Return the ISO week number for the current or specified date." _
& vbCrLf & vbCrLf _
& "Usage: CSCRIPT.EXE //NoLogo WEEK.VBS [ date ]" _
& vbCrLf & vbCrLf _
& "Where: ""date"" is an optional date to calculate the week number for" _
& vbCrLf _& " (default is today)" _
& vbCrLf & vbCrLf _
& "Notes: The ISO week number will be displayed on screen, returned as return" _
& vbCrLf _& " code, and stored in an environment variable %Week%." _
& vbCrLf _& " 0 means the last week (52 or 53) of the previous year." _
& vbCrLf _& " If ambiguous, the date is interpretated according to the computer's" _
& vbCrLf _& " regional/international settings." _
& vbCrLf _& " To make the date unambiguous, use the ISO format (yyyy-mm-dd)." _
& vbCrLf _& " To distinguish between errors and week numbers, -1 is used for errors." _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" _
& vbCrLf _& "http://www.robvanderwoude.com"
WScript.Quit -1
End Sub
page last modified: 2025-10-11; loaded in 0.0072 seconds