Thanks,
Sheel
Dim dtNow : dtNow = Now
Dim sRes
WScript.Echo 0, dtNow
sRes = Right( "0" & Day( dtNow ), 2 ) _
& Right( "0" & Month( dtNow ), 2 ) _
& Right( Year( dtNow ), 2 ) _
& "-" _
& Right( "0" & Hour( dtNow ), 2 ) _
& Right( "0" & Minute( dtNow ), 2 )
WScript.Echo 1, sRes
sRes = DNIPrintF( "{0:ddMMyy-HHmm}", Array( dtNow ) )
WScript.Echo 2, sRes
Dim oRE : Set oRE = New RegExp
oRE.Pattern = "^(\d\d).(\d\d).\d\d(\d\d) (\d\d):(\d\d):\d\d$"
WScript.Echo 3, oRE.Replace( CStr( dtNow ), "$1$2$3-$4$5" ) ' "$2$1.." for us
' ----------------------------------------------------------------------------
'' DNIPrintF( sFmt, aItems ) - use .NET to sprintf()
' ----------------------------------------------------------------------------
Function DNIPrintF( sFmt, aItems )
Dim oSB : Set oSB = CreateObject( "System.Text.StringBuilder" )
oSB.AppendFormat_4 sFmt, (aItems)
DNIPrintF = oSB.ToString()
End Function
output:
=== fmtDate: format date ========
0 28.11.2007 21:36:43
1 281107-2136
2 281107-2136
3 281107-2136
=== fmtDate: 0 done (00:00:00) ==
> sRes = Right( "0" & Day( dtNow ), 2 ) _
> & Right( "0" & Month( dtNow ), 2 ) _
> & Right( Year( dtNow ), 2 ) _
> & "-" _
> & Right( "0" & Hour( dtNow ), 2 ) _
> & Right( "0" & Minute( dtNow ), 2 )
sRes = Year(dtNow)*1e4 + Month(dtNow)*1e2 + Day(dtNow ) _
& "-" & Right(1e4 + Hour(dtNow)*1e2 + Minute(dtNow), 4)
is better.
> Dim oRE : Set oRE = New RegExp
> oRE.Pattern = "^(\d\d).(\d\d).\d\d(\d\d) (\d\d):(\d\d):\d\d$"
> WScript.Echo 3, oRE.Replace( CStr( dtNow ), "$1$2$3-$4$5" ) '
>"$2$1.." for us
Any method based in CStr of a CDate is unreliable, unless there is
absolute control over the default date field order. Some Europeans use
DMY, some choose YMD.
Query : given such a RegExp, exactly how best can one, in (Web) VBS,
obtain, in separate variables or in an array, the values corresponding
to $1 .. $5 ?
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
>> Query : given such a RegExp, exactly how best can one, in (Web) VBS,
>> obtain, in separate variables or in an array, the values corresponding
>> to $1 .. $5 ?
>use oRE.Execute( <Text> )( <NumberOfMatch> ).SubMatches( <NumberOfParen> )
Thanks. SubMatches is the clue. I've not yet found out how I should
check what Execute returns for no matches, but can work round using "for
each X in ...". Code is, temporarily, in <URL:http://www.merlyn.demon.
co.uk/vb-date3.htm>.
Since the present RegExp pattern starts ^ and ends $, the number of
matches will be 0 or 1.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm vb-dates.htm pas-time.htm critdate.htm etc.