?
Solved

ASP Format Function

Posted on 2001-06-13
11
Medium Priority
?
1,463 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
[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
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 11

Expert Comment

by:ASPGuru
ID: 6187833
there are several:

FormatCurrency
FormatDateTime
FormatNumber
FormatPercent

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
LVL 5

Accepted Solution

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

770 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