[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
11
Medium Priority
?
1,466 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 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

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!

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…

649 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