Solved

ASP Format Function

Posted on 2001-06-13
11
1,462 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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