Dr
Mon Aug 14 16:19:30 CDT 2006
JRS: In article <OK6v#u4vGHA.1956@TK2MSFTNGP02.phx.gbl>, dated Mon, 14
Aug 2006 12:23:52 remote, seen in news:microsoft.public.scripting.vbscri
pt, Alexander Mueller <millerax@hotmail.com> posted :
>youyoupapayou@gmail.com schrieb:
>> I would like to make a date conversion from DD/MM/YYY hh:mm:ss to
>> YYYYMMDDhhmmss in vbscript.
DD/MM/YY or DD/MM/YYYY ?
>As long as VBScript correctly identifies a string as date
>you can use CDate and some VB-Date-functions.
No; it is also necessary that it reads the date correctly. 24/12/2004
may be read correctly as December; but that does not prove that
04/12/2004 will not be read as April.
>msgbox YYYYMMDDhhmmss ("24/12/004 12:00:00")
>
>
>Function YYYYMMDDhhmmss(vDat)
>
> If varType(vDat) = vbString Then
> YYYYMMDDhhmmss = YYYYMMDDhhmmss(CDate(vDat))
>
> ElseIf varType(vDat) = vbDate Then
> YYYYMMDDhhmmss = _
> Year(vDat) _
> & Right("0" & Month(vDat),2) _
> & Right("0" & Day(vDat),2) _
> & Right("0" & Hour(vDat),2) _
> & Right("0" & Minute(vDat),2) _
> & Right("0" & Second(vDat),2)
> End If
>
>End function
YYYYMMSShhmmss = _
((((Year(D)*100+Month(D))*100+Day(D))*100+ _
Hour(D))*100+Minute(D))*100+Second(D)
is shorter.
Your code gives me 20241204120000 for that YYY year, & is OK for
24/12/2004 - but for 07/12/2004 it gives 20040712120000.
If the input is in exact form, it would be better to use a RegExp edit -
I cannot test that in VBS, but in Javascript :-
S = "07/12/2004 12:00:00"
S = S.replace(/^(\d\d).(\d\d).(\d\d\d\d) (\d\d).(\d\d).(\d\d)$/,
"$3$2$1$4$5$6")
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:
http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:
http://www.merlyn.demon.co.uk/vb-dates.htm> VBscript dates, sources.
<URL:
http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.