# ASP Format Function

Is there a format function in ASP similar to the one in VB, i.e. formatted_string = FORMAT(unformatted_string,"0000")?
###### Who is Participating?

x

Commented:
Try this

intDate = Date()

intMonth = DatePart("m", intDate)

If intMonth < 10 Then
intMonth = "0" & intMonth
End If
Response.Write "<br>" & intMonth
0

Commented:
there are several:

FormatCurrency
FormatDateTime
FormatNumber
FormatPercent

0

Commented:
0

Commented:
You can use Formatdatetime, formatNumber, formatcurrency etc.

Syntax

FormatDateTime(Date[, NamedFormat])
Function GetCurrentDate
' FormatDateTime formats Date in long date.
GetCurrentDate = FormatDateTime(Date, 1)
End Function

Syntax
The FormatNumber function syntax has these parts:

Function FormatNumberDemo
Dim MyAngle, MySecant, MyNumber
MyAngle = 1.3                ' Define angle in radians.
MySecant = 1 / Cos(MyAngle)  ' Calculate secant.
FormatNumberDemo = FormatNumber(MySecant,4) ' Format MySecant to four decimal places.
End Function

etc. etc.
What do you want to achieve ?

0

Author Commented:
I tried FormatNumber(Month(Date()),0,-1) to get a leading zero on the system month, but it didn't work.  Any suggestions?
0

Commented:
To get "a leading zero on the system month, "
use month funciton

Dim MyVar
MyVar = Month(Now) ' MyVar contains the number corresponding to
' the current month.

0

Author Commented:
I tried that and got 6, not 06.
0

Commented:
Is this that you want?

<%

Dim pStr

pStr = CStr(pNumber)
else
for iCount = 1 to (pLeadingZeroCount-Len(pStr))
pStr = "0" & pStr
next
end if
End Function

Response.Write "Number: " & LeadingZero(99, 4)

%>
0

Author Commented:
I guess that's the only way to do it.  Thanks!
0

Commented:
> I tried that and got 6, not 06.

right("0" & DatePart("m", intDate),2)
0

Author Commented:
There we go, thanks ASPGuru!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.