Solved

ASP Format Function

Posted on 2001-06-13
11
1,422 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
ID: 6187833
there are several:

FormatCurrency
FormatDateTime
FormatNumber
FormatPercent

0
 
LVL 11

Expert Comment

by:ASPGuru
ID: 6187841
0
 
LVL 20

Expert Comment

by:jitganguly
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
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
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

by:jitganguly
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Accepted Solution

by:
raizon earned 100 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

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

Expert Comment

by:daniel_c
ID: 6187910
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
ID: 6187919
I guess that's the only way to do it.  Thanks!
0
 
LVL 11

Expert Comment

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

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

Author Comment

by:arichee
ID: 6188066
There we go, thanks ASPGuru!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 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

20 Experts available now in Live!

Get 1:1 Help Now