Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format a date string 2

Status
Not open for further replies.

CrystalizeCanada

Instructor
Mar 4, 2009
141
CA
Hi there,

Is there a function in VBSCript that will convert a date to a string and allow me to have it in the format I want for example 04-11-2009 i.e. dd-mm-yyyy.

A couple of functions I've tried haven't worked. The format function which works in VBA doesn't work here. Cstr doesn't allow me to give it the format I want.

Any ideas?

Thanks

G

Gordon BOCP
Crystalize
 
A starting point:
MsgBox Right("0" & Day(yourDate), 2) & "-" & Right("0" & Month(yourDate), 2) & "-" & Year(yourDate)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This worked great. Used your & (instead of the +) I was using and made it simpler (didn't have to use Cstr).

Tx again

G

Gordon BOCP
Crystalize
 
PHV,

I was trying something similar to that a few weeks ago, but using the Right() function makes so much more sense than the way I was doing it, which was to add the leading only 0 if the number was less than 10. I knew it seemed like a lot of coding for a simple task.

Good thinking!

Thanks,
Andrew

[medal] Hard work often pays off over time, but procrastination pays off right now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top