For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > February 2005 > Need to dynamicly create a date in format "yymmdd"









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Need to dynamicly create a date in format "yymmdd"
JP

2005-02-08, 4:01 pm

I know that this is a VB forum, but I need help with dynamically creating a
date in a special format "yymmdd" but not in VB but in VBScript. I though
somebody might know. E.g 050208 would be today's date. Is there any way to do
this in VBScript? The Date function returns "mm/dd/yyyy". Also is there
anywhere here a VBScript development newsgroup?

Thanks alot,
JP
Randy Birch

2005-02-08, 4:01 pm

Actually, the Date function returns the date in the user-specified short
date format via regional settings. If you haven't tweaked this, the install
format is mm/dd/yyyy. Use Format$ to change to a custom-defined format for
display.

--


Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/


"JP" <JP@discussions.microsoft.com> wrote in message
news:CF309EE1-A514-4A0E-9619-2B1D740C4239@microsoft.com...
:I know that this is a VB forum, but I need help with dynamically creating a
: date in a special format "yymmdd" but not in VB but in VBScript. I though
: somebody might know. E.g 050208 would be today's date. Is there any way to
do
: this in VBScript? The Date function returns "mm/dd/yyyy". Also is there
: anywhere here a VBScript development newsgroup?
:
: Thanks alot,
: JP

Karl E. Peterson

2005-02-08, 4:01 pm

JP wrote:
> I know that this is a VB forum, but I need help with dynamically
> creating a date in a special format "yymmdd" but not in VB but in
> VBScript. I though somebody might know. E.g 050208 would be today's
> date. Is there any way to do this in VBScript?


No direct way, but it's pretty easy with some string gynastics:

Option Explicit

Dim Today
Today = Right("0" & Day(Now), 2)
Today = Right("0" & Month(Now), 2) & Today
Today = Right(Year(Now), 2) & Today
WScript.Echo Today

> Also is there anywhere here a VBScript development newsgroup?


Well, there's microsoft.public.scripting.vbscript for one.

Later... Karl
--
[Microsoft Basic: 1976-2001, RIP]


Karl E. Peterson

2005-02-08, 4:01 pm

Randy Birch wrote:
> Actually, the Date function returns the date in the user-specified
> short date format via regional settings. If you haven't tweaked
> this, the install format is mm/dd/yyyy. Use Format$ to change to a
> custom-defined format for display.


Unfortunately, Format isn't supported by VBS, and the FormatDateTime function doesn't
take user-supplied strings. :-(
--
[Microsoft Basic: 1976-2001, RIP]

[color=darkred]
> "JP" <JP@discussions.microsoft.com> wrote in message
> news:CF309EE1-A514-4A0E-9619-2B1D740C4239@microsoft.com...



Jeff Johnson [MVP: VB]

2005-02-08, 9:02 pm


"Karl E. Peterson" <karl@mvps.org> wrote in message
news:OGqHGNhDFHA.3340@TK2MSFTNGP10.phx.gbl...

> No direct way, but it's pretty easy with some string gynastics:


Is that something you can only do with female strings...?


Karl E. Peterson

2005-02-08, 9:02 pm

Jeff Johnson [MVP: VB] wrote:
> "Karl E. Peterson" <karl@mvps.org> wrote ...
>
>
> Is that something you can only do with female strings...?


Oh, I dunno, some say that about doing Split's, too...
--
[Microsoft Basic: 1976-2001, RIP]


JP

2005-02-08, 9:02 pm

Thanks Carl! You're great!


"Karl E. Peterson" wrote:

> JP wrote:
>
> No direct way, but it's pretty easy with some string gynastics:
>
> Option Explicit
>
> Dim Today
> Today = Right("0" & Day(Now), 2)
> Today = Right("0" & Month(Now), 2) & Today
> Today = Right(Year(Now), 2) & Today
> WScript.Echo Today
>
>
> Well, there's microsoft.public.scripting.vbscript for one.
>
> Later... Karl
> --
> [Microsoft Basic: 1976-2001, RIP]
>
>
>

Randy Birch

2005-02-09, 4:01 pm

Wow - didn't know that! That's an omission.

--


Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/


"Karl E. Peterson" <karl@mvps.org> wrote in message
news:u0oXmNhDFHA.1188@tk2msftngp13.phx.gbl...
: Randy Birch wrote:
: > Actually, the Date function returns the date in the user-specified
: > short date format via regional settings. If you haven't tweaked
: > this, the install format is mm/dd/yyyy. Use Format$ to change to a
: > custom-defined format for display.
:
: Unfortunately, Format isn't supported by VBS, and the FormatDateTime
function doesn't
: take user-supplied strings. :-(
: --
: [Microsoft Basic: 1976-2001, RIP]
:
:
: > "JP" <JP@discussions.microsoft.com> wrote in message
: > news:CF309EE1-A514-4A0E-9619-2B1D740C4239@microsoft.com...
: >> I know that this is a VB forum, but I need help with dynamically
: >> creating a date in a special format "yymmdd" but not in VB but in
: >> VBScript. I though somebody might know. E.g 050208 would be today's
: >> date. Is there any way to do this in VBScript? The Date function
: >> returns "mm/dd/yyyy". Also is there anywhere here a VBScript
: >> development newsgroup?
: >>
: >> Thanks alot,
: >> JP
:
:
:

Dick Grier

2005-02-09, 4:01 pm

(K)arl

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.


Jeff Johnson [MVP: VB]

2005-02-09, 9:00 pm


"Randy Birch" <rgb_removethis@mvps.org> wrote in message
news:%23kFFI6rDFHA.2220@TK2MSFTNGP09.phx.gbl...

> Wow - didn't know that! That's an omission.


And a perfect example of why we redirect script questions to another group.


Karl E. Peterson

2005-02-10, 4:00 am

Randy Birch wrote:
>
> Wow - didn't know that! That's an omission.


Drives me nutz everytime I need to use it, yep.
--
[Microsoft Basic: 1976-2001, RIP]


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com