VBS - How to show date as ddmmyy ?

September 9, 2009 at 03:22:25
Specs: Windows XP, 2gb

I'm using vbs to autoupdate passwords and need to use the current date but in a specific format.

This code returns the date in this format "09/09/2009"

myDateString = FormatDateTime(Date(), 0)
msgBox(myDateString)

But I need the date to be returned in this format "090909" - six numerals and no slashes. The closest I can get is this:

myDateString = FormatDateTime(Date(), 0)

MSGBox(Day(myDateString) & Month(myDateString) & Year(myDateString))

This returns the date as "992009". Is is possible to get VB to show me the date like I need; "090909", in other words "ddmmyy" ?

I've played around for a few hours but just can't seem to get it working.

Any help would be greatly appreciated.


See More: VBS - How to show date as ddmmyy ?

Report •


#1
September 9, 2009 at 05:39:48

strDayOfMonth = right("0" & day(date()),2)
strMonth = right("0" & month(date()),2)
strYear = right (year(date()),2)
msgbox(strDayOfMonth & strMonth & strYear)

or samething, but if you have to put the date in more then one place it may be easier to set it as a variable in the format you like:

strDayOfMonth = right("0" & day(date()),2)
strMonth = right("0" & month(date()),2)
strYear = right (year(date()),2)
DDMMYY = strDayOfMonth & strMonth & strYear
msgbox(DDMMYY)


Report •

#2
September 9, 2009 at 06:32:38

That's exactly what I wanted. Thanks very much for that gtaion.

Report •

Related Solutions


Ask Question