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

convert date.today value

Status
Not open for further replies.

slybitz

Technical User
Mar 25, 2005
113
US
Hello!

I am putting date.today into a variable called dte but I want to convert the date format from, for example, 12/10/2006 to 20061210. How can I do this? I know it's probably something simple but I can't seem to find the answer.

Thanks for your help!
 
Assuming your date it mm/dd/yyyy:


Dim DateString As String

DateString = Year(dt).ToString & Month(dte).ToString & Day(dte).ToString

If you need leading zeroes on days and months that are less than 10 (e.g., 9/9/2006), then do this:

DateString = Year(dt).ToString

If Month(dte) < 10 Then
DateString &= "0" & Month(dte).ToString
Else
DateString &= Month(dte).ToString
End If

If Day(dte) < 10 Then
DateString &= "0" & Day(dte).ToString
Else
DateString &= Day(dte).ToString
End If

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top