Solved

ASP Format Function

Posted on 2001-06-13
11
1,411 Views
Last Modified: 2007-11-27
Is there a format function in ASP similar to the one in VB, i.e. formatted_string = FORMAT(unformatted_string,"0000")?
0
Comment
Question by:arichee
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 11

Expert Comment

by:ASPGuru
Comment Utility
there are several:

FormatCurrency
FormatDateTime
FormatNumber
FormatPercent

0
 
LVL 11

Expert Comment

by:ASPGuru
Comment Utility
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
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
FormatNumber(Expression [,NumDigitsAfterDecimal [,IncludeLeadingDigit [,UseParensForNegativeNumbers [,GroupDigits]]]])
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

by:arichee
Comment Utility
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

by:jitganguly
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 5

Accepted Solution

by:
raizon earned 100 total points
Comment Utility
Try this

intDate = Date()

intMonth = DatePart("m", intDate)

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

Author Comment

by:arichee
Comment Utility
I tried that and got 6, not 06.
0
 
LVL 7

Expert Comment

by:daniel_c
Comment Utility
Is this that you want?

<%

Function LeadingZero(pNumber, pLeadingZeroCount)
   Dim pStr

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


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

%>
0
 

Author Comment

by:arichee
Comment Utility
I guess that's the only way to do it.  Thanks!
0
 
LVL 11

Expert Comment

by:ASPGuru
Comment Utility
> I tried that and got 6, not 06.

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

Author Comment

by:arichee
Comment Utility
There we go, thanks ASPGuru!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now