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

adding leading zero to date using DatePart

Status
Not open for further replies.

cic

Technical User
Apr 12, 2001
28
US
I am having problems making the month and date two digits. I have tried "mm" and "dd" however I get the following error.

Invalid procedure call or argument: 'DatePart'

TodayDate = Cstr(DatePart("m",date)) + Cstr(DatePart("d",date)) + Cstr(DatePart("yyyy",date))

please help
 
<%
' get each date component
thisMonth = datepart(&quot;m&quot;,date)
thisDay = datepart(&quot;d&quot;,date)
thisYear = datepart(&quot;yyyy&quot;,date)

' check for the length of the month and day components
if len(thisMonth) < 2 then thisMonth = &quot;0&quot; & thisMonth
if len(thisDay) < 2 then thisDay = &quot;0&quot; & thisDay

' Create the date in your format you posted above
TodayDate = thisMonth & thisDay & thisYear

' write out the new formatted date
response.write TodayDate

' You can also do this, but the format will be mm/dd/yyyy
response.write FormatDateTime(date(),vbShortDate)
%> regards,
Brian
AOL IM: FreelanceGaines

AG00280_.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top