(view source code of setdate.vbs as plain text)
Option Explicit
Dim dtmNow
Dim strDay, strDoW, strDoY, strMonth, strQuarter, strWeek, strYear
Dim wshShell, wshSystemEnv
Set wshShell = CreateObject( "WScript.Shell" )
If WScript.Arguments.Count > 0 Then Syntax
Set wshSystemEnv = wshShell.Environment( "SYSTEM" )
' Take a "snapshot" of the current date and time,
' because setting the variables may take quite a while
dtmNow = Now
' Set the "components" in environment variables
strDay = Right( "0" & DatePart( "d", dtmNow ), 2 )
strDoW = DatePart( "w", dtmNow )
strDoY = Right( "00" & DatePart( "y", dtmNow ), 3 )
strMonth = Right( "0" & DatePart( "m", dtmNow ), 2 )
strQuarter = DatePart( "q", dtmNow )
strWeek = Right( "0" & DatePart( "ww", dtmNow ), 2 )
strYear = DatePart( "yyyy", dtmNow )
wshSystemEnv( "Date.Day" ) = strDay
wshSystemEnv( "Date.DoW" ) = strDoW
wshSystemEnv( "Date.DoY" ) = strDoY
wshSystemEnv( "Date.Month" ) = strMonth
wshSystemEnv( "Date.Quarter" ) = strQuarter
wshSystemEnv( "Date.Week" ) = strWeek
wshSystemEnv( "Date.Year" ) = strYear
Set wshSystemEnv = Nothing
Set wshShell = Nothing
Sub Syntax
WScript.Echo vbCrLf _
& "SetDate.vbs, Version 1.10" _
& vbCrLf _
& "Set the current date in a set of environment variables" _
& vbCrLf & vbCrLf _
& "Usage: CSCRIPT SETDATE.VBS" _
& vbCrLf & vbCrLf _
& "Notes: Schedule this command every day at midnight AND at system startup." _
& vbCrLf _
& " From then on, all batch files and programs will have a set of" _
& vbCrLf _
& " environment variables available that can be used in log files names" _
& vbCrLf _
& " etcetera." _
& vbCrLf _
& " The following variables will be available (with the number of digits" _
& vbCrLf _
& " between parentheses):" _
& vbCrLf _
& " Date.Day (2) Date.DoW (1) Date.DoY (3) Date.Month (2)" _
& vbCrLf _
& " Date.Quarter (1) Date.Week (2) Date.Year (4)" _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" _
& vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Quit 1
End Sub
page last modified: 2024-04-16; loaded in 0.0097 seconds