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 With ' 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 _ & "Date2ISO.vbs, Version 1.02" _ & vbCrLf _ & "Convert any date/time to ISO date/time" _ & vbCrLf & vbCrLf _ & "Usage: CSCRIPT.EXE //NoLogo Date2ISO.vbs date [ time ] [ /D | /T ]" _ & vbCrLf & 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 & vbCrLf _ & "Note: If the specified date is ambiguous, the current user's date" _ & vbCrLf _ & " and time format is assumed." _ & vbCrLf & vbCrLf _ & "Written by Rob van der Woude" _ & vbCrLf _ & "http://www.robvanderwoude.com" WScript.Quit 1 End Sub