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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing date format to yymmdd 1

Status
Not open for further replies.

ciberperson

Programmer
Aug 31, 2000
29
CA
I would like to convert my date to a format of yymmdd without separators in order to use as a string in a file name. How do I convert the system date to this format?
 
I'm new to VBScript (but familiar with VB). From what I have gathered, VBScript doesn't supply a built-in Format() function like VB, otherwise this would only take one line.

Dim dt
Dim sp
Dim res

dt=Now()
sp=Instr(1,dt," ")
yr=Mid(dt,sp-2,2)
dy=Mid(dt,sp-5,2)
mo=Mid(dt,1,Instr(1,dt,"/")-1)
If (Len(dy)=1) Then dy="0" & dy
If (Len(mo)=1) Then mo="0" & mo
res=yr & mo & dy

Cheers
 
Here is another method.

dim dtmMonth, dtmDay, dtmYear, dtmMDY

dtmMonth = Month(date)
dtmDay = Day(date)
dtmYear = Year(date)
dtmMDY = dtmMonth & dtmDay & dtmYear

A format function would be much nicer. :)


 
Hey thanks for those great replies. I appreciate your time and effort and I learned something that I really needed to know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top