Format Special Data ASP Tutorial - ASP Web Pro
  Active Server Pages Programming by ASP Web Pro

ASP Tutorials

FORMAT SPECIAL DATA

If you want to display numbers from a database on your web page, chances are you will have to do some formatting to get your data to display the way you want it to. Here are a few examples.

Dates:

<% Response.Write FormatDateTime(Date, vbShortDate) %>

<% Response.Write FormatDateTime(Date, vbLongDate) %>

There are a lot of ways to display dates. The first line returns the short date in a 13/05/2008 format while the second line returns the long date in a 13 May 2008 format.

Times:

<% Response.Write FormatDateTime(Time, vbShortTime) %>

<% Response.Write FormatDateTime(Time, vbLongTime) %>

There are a lot of ways to display dates. The first line returns the short date in a 10:14 format while the second line returns the long date in a 10:14:14 format. If you want the display to update and continue counting seconds live on the users browser, you need to use JavaScript to do this.

Currency:

<% Response.Write FormatCurrency ( Variable, -1, -2, -2, -2) %>

When displaying currency, these are the system default settings. The first setting Variable is the variable containing the amount. The second setting is the number of decimal places. The third setting specifies not to use leading zeros for numbers less than one. The fourth setting specifies not to use parenthesis around negative numbers. The fifth setting specifies not to use a comma to separate number larger than one thousand. As you can see, the third, fourth, and fifth settings are in the "off" position by default. To turn these settings "on", replace their respective -2 setting with a -1. To specify the number of decimals to use, simply change the second setting from -1 to whatever number you want.

Numbers:

<% Cint (Variable) %>

When displaying numbers, Cint displays the Integer subtype which takes up 2 bytes in memory and can contain a value between -32,768 and 32,767.

<% Clng (Variable) %>

When displaying numbers, Clng displays the Long subtype which takes up 4 bytes in memory and can contain a value between -2,147,483,648 and 2,147,483,647.

<% Cdbl (Variable) %>

When displaying numbers, Cdbl displays the Double subtype which takes up 8 bytes in memory, 4 bytes of which are used for contatining fractional values. It is a very precise subtype used for advanced mathematical expressions including fractional or decimal values.

These are just a few of the most common techniques for formatting special data. We will continue to add more formatting techniques to this page as time goes on so be sure to check back here for new additions.

Happy Formatting!

< Back to Tutorials


 

 

Main Menu
Home
ASP Scripts
ASP Tutorials
JavaScripts
Awards
Contact Us

Email This Page

Other Resources
ASP Web Hosting
Search Engine Submission
Programming Help

 

 

 

Other ASP Web Sites

Site Map

 

Last Updated:
13 May 2008