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

Rookie function question 1

Status
Not open for further replies.

Pekka

Technical User
Mar 19, 2002
107
FI
Hello,
I'm really newbie in VBA coding but I'm trying to do a function which would return current date in following format:'20020607'. If somebody could tell me what I'm doing wrong I would appreciate it.

Function pvm2()
Dim mm, dd, yyyy
mm = Month(Date)
dd = Day(Date)
yyyy = Year(Date)
If mm < 10 Then
mm = &quot;0&quot; & mm
Else
mm = mm
End If
If dd < 10 Then
dd = &quot;0&quot; & dd
Else
dd = dd
End If
pvm2 = yyyy & &quot; & mm &quot; & dd


End Function
 
OK.....

You,ve got this all wrong!!! There already is a function to do this called Format.....

What you need is Format(Date(), &quot;yyyymmdd&quot;)

Hope that helps.

Craig
 
Thanks Craig,
... yeah I know... a wheel has allready been invented and maybe I should not try to invent it again.

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top