[2 days left] Whatâ€™s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

# ASP Format Function

Posted on 2001-06-13
Medium Priority
1,466 Views
Is there a format function in ASP similar to the one in VB, i.e. formatted_string = FORMAT(unformatted_string,"0000")?
0
Question by:arichee
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 3
• 2
• +2

LVL 11

Expert Comment

ID: 6187833
there are several:

FormatCurrency
FormatDateTime
FormatNumber
FormatPercent

0

LVL 11

Expert Comment

ID: 6187841
0

LVL 20

Expert Comment

ID: 6187842
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 Comment

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

LVL 20

Expert Comment

ID: 6187899
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

LVL 5

Accepted Solution

raizon earned 400 total points
ID: 6187903
Try this

intDate = Date()

intMonth = DatePart("m", intDate)

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

Author Comment

ID: 6187909
I tried that and got 6, not 06.
0

LVL 7

Expert Comment

ID: 6187910
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 Comment

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

LVL 11

Expert Comment

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

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

Author Comment

ID: 6188066
There we go, thanks ASPGuru!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is tâ€¦
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interactâ€¦
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on tâ€¦
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrasâ€¦
###### Suggested Courses
Course of the Month14 days, 17 hours left to enroll