Hi,
I have a problem with my VBS. I want to replace an old date with the
currently date in a special file. The Replace-Funktion works but the
replaced month is "2". I want to replace it with "02". Do you have any
Idea how this could work?

Heute = Date
contents=replace(contents, a, Year(Heute) & "-" & Month(Heute) & "-" &
Day(Heute)")

The result should be: 2007-02-23
Kind regards
Tina

Re: Design Month "2" into "02" by ekkehard

ekkehard
Fri Feb 23 07:36:32 CST 2007

christina.tina@gmx.de wrote:
> Hi,
> I have a problem with my VBS. I want to replace an old date with the
> currently date in a special file. The Replace-Funktion works but the
> replaced month is "2". I want to replace it with "02". Do you have any
> Idea how this could work?
>
> Heute = Date
> contents=replace(contents, a, Year(Heute) & "-" & Month(Heute) & "-" &
> Day(Heute)")
>
> The result should be: 2007-02-23
> Kind regards
> Tina
>
Dim dtHeute : dtHeute = Date
Dim sHeute : sHeute = Year( dtHeute ) & "-" _
& Right( "0" & Month( dtHeute ), 2 ) & "-" _
& Right( 100 + Day( dtHeute ), 2 )
Dim sA : sA = "01.01.1970"
Dim sContents : sContents = "abcd" + sA + "ef"
WScript.Echo sContents
sContents = Replace( sContents, sA, sHeute )
WScript.Echo sContents

The second method to prepend a "0" conditionally is (c) M. Harris.
Output:

abcd01.01.1970ef
abcd2007-02-23ef


Re: Design Month "2" into "02" by christina

christina
Fri Feb 23 08:31:13 CST 2007

On 23 Feb., 14:36, "ekkehard.horner" <ekkehard.hor...@arcor.de> wrote:
> christina.t...@gmx.de wrote:
> > Hi,
> > I have a problem with my VBS. I want to replace an old date with the
> > currently date in a special file. The Replace-Funktion works but the
> > replaced month is "2". I want to replace it with "02". Do you have any
> > Idea how this could work?
>
> > Heute = Date
> > contents=replace(contents, a, Year(Heute) & "-" & Month(Heute) & "-" &
> > Day(Heute)")
>
> > The result should be: 2007-02-23
> > Kind regards
> > Tina
>
> Dim dtHeute : dtHeute = Date
> Dim sHeute : sHeute = Year( dtHeute ) & "-" _
> & Right( "0" & Month( dtHeute ), 2 ) & "-" _
> & Right( 100 + Day( dtHeute ), 2 )
> Dim sA : sA = "01.01.1970"
> Dim sContents : sContents = "abcd" + sA + "ef"
> WScript.Echo sContents
> sContents = Replace( sContents, sA, sHeute )
> WScript.Echo sContents
>
> The second method to prepend a "0" conditionally is (c) M. Harris.
> Output:
>
> abcd01.01.1970ef
> abcd2007-02-23ef

It works! Thank you so much!


Re: Design Month "2" into "02" by Doug

Doug
Fri Feb 23 13:19:46 CST 2007

On Feb 23, 7:46 am, christina.t...@gmx.de wrote:
> Hi,
> I have a problem with my VBS. I want to replace an old date with the
> currently date in a special file. The Replace-Funktion works but the
> replaced month is "2". I want to replace it with "02". Do you have any
> Idea how this could work?
>
> Heute = Date
> contents=replace(contents, a, Year(Heute) & "-" & Month(Heute) & "-" &
> Day(Heute)")
>
> The result should be: 2007-02-23
> Kind regards
> Tina

this is what I do...

mo = month(now)
if mo < 10 then mo = "0" & mo
da = day(now)
if da < 10 then da = "0" & da

resultdate = year(now) & "-" & mo & "-" & da