Option Explicit Dim blnDate, blnTime Dim dtmDate Dim intDay, intFormat, intHour, intMin, intMonth, intSec, intUTC, intValid, intYear Dim strISO With WScript. Arguments 'Check command line arguments If. Unnamed. Count = 0 Then dtmDate = Now If. Unnamed. Count> 0 Then dtmDate =. Unnamed (0) If. Unnamed. Count> 1 Then dtmDate = dtmDate & "&. Unnamed (1) If. Unnamed. Count> 2 Then dtmDate = dtmDate & "" &. Unnamed (2) If. Unnamed. Count> 3 Then Syntax On Error Resume Next DtmDate = CDate (dtmDate) If Err Then On Error Goto 0 Syntax End If On Error Goto 0 If Not IsDate (dtmDate) Then Syntax IntValid = 0 BlnDate = True BlnTime = True If. Named. Exists ("D") Then BlnDate = True BlnTime = False IntValid = intValid + 1 End If If. Named. Exists ("T") Then BlnDate = False BlnTime = True IntValid = intValid + 1 End If If intValid <>. Named. Count Then Syntax If intValid> 1 Then Syntax End 'Format the output string IntYear = DatePartLZ ("yyyy", dtmDate) IntMonth = DatePartLZ ("m", dtmDate) IntDay = DatePartLZ ("d", dtmDate) IntHour = DatePartLZ ("h", dtmDate) IntMin = DatePartLZ ("n", dtmDate) IntSec = DatePartLZ ("s", dtmDate) If blnDate Then strISO = intYear & "-" & intMonth & "-" & intDay If blnTime Then strISO = strISO & "" & intHour & ":" & intMin & ":" & intSec 'Display the result WScript. Echo Trim (strISO) Function DatePartLZ (myInterval, myDate) 'Add a leading zero to the DatePart () if necessary Dim strDatePart StrDatePart = DatePart (myInterval, myDate) If Len (strDatePart) <2 Then strDatePart = "0" & strDatePart DatePartLZ = strDatePart End Function Sub Syntax WScript. Echo vbcrlf _ & Amp; "Date2ISO. vbs, Version 1.02 "_ & VbCrLf _ & "Convert any date/time to ISO date/time "_ & VbCrLf _ & "Usage: CSCRIPT. EXE // NoLogo Date2ISO. vbs date [time] [/D |/T]" _ & VbCrLf _ & "Where:" "date" "is the date to convert (default: current date/time )"_ & VbCrLf _ & "Time" "is the optional time to convert "_ & VbCrLf _ & "/D return date only (default: both date and time )"_ & VbCrLf _ & "/T return time only (/D and/T are mutually exclusive )"_ & VbCrLf _ & "Note: If the specified date is ambiguous, the current user's date "_ & VbCrLf _ & "And time format is assumed ."_ & VbCrLf _ & "Written by Rob van der Woude "_ & VbCrLf _ & "Http://www.robvanderwoude.com" WScript. Quit 1 End Sub |