Technical References - [format]

To apply formats for Dates or Times other than the current date and time, use [format]

Format is used for text and numbers. Format will also apply formatting to dates and times provided they are converted to numbers first. To convert a date or time into a number, enclose them with curly braces, and wrap them in a [math] context. This will convert dates into number of days since 00/00/0000, and times into number of seconds since midnight. And then they can be wrapped in a format context for custom formatting.

To convert to a number:
[math]{08/14/2008}[/math] --> 733633
[math]{10:12:07}[/math] --> 36727

Now we can apply formatting using Days_To_Date, and formatting specifiers:
1. [Format Days_To_Date %m/%d/%y][math]{08/14/2008}[/math][/format]
2. [format Days_To_Date %A, %B %d, %Y][math]{08/14/2008}[/math][/Format]
3. [format Days_To_Date %A, %B %d, %Y]733633[/format]
4. [format Days_To_Date]733633[/Format]
5. [format Seconds_To_Time %I:%M:%S %p][math]{10:12:07}[/math][/format]
6. [format Seconds_To_Time %I:%M:%S %p]36727[/format]

Results would be:

1. 08/14/08
2. Thursday, August 14, 2008
3. Thursday, August 14, 2008
4. 08/14/2008
5. 10:12:07 AM
6. 10:12:07 AM

Note that the [date] formats are the same, but work specifically on the [date] tag, which resolves to the current date only. If you are retrieving dates from a database, use Format as above.

The %d designator returns a 2 digit date (August 05, 2008), but for single digit dates, this looks bad. There's a workaround. Separate the components, and wrap the %d piece in [math] tags, and it will get rid of the leading zero.

[math][format days_to_date %d][math]{[date]}[/math][/format][/math]

Another way would be using grep:
[grep search= 0&replace= ]
[format Days_To_Date %A, %B %d, %Y][math]{[date]}[/math][/format]

[format FormatSpec]Text or Number[/Format]
Formats text or numbers in various widths or currency formats.
To display numbers with various decimal points or currency formats, surround the number or text with a [format] context.

Numeric formatting works with comma separators for decimal point (non-US style, such as [format 6,2f][math]39/7[/math][/format] yields 7,46 instead of 7.46)

[format 10.2f]99.5[/Format] (f stands for floating-point number)
[format 10s]Hello[/format] (s stands for string of text)
[format Days_To_Date %m/%d/%y]195462[/format]
[format Seconds_To_Time]49768[/format]
[format Seconds_To_Time %I:%M:%S %p]49768[/format]
[format thousands 14.2f]394363210[/format]
[format thousands 14,2f]394363210[/format]
[format thousands .3d]7[/Format] (d stands for decimal number)

The number displays right-justified with enough preceding spaces and digits after the decimal point to fill the exact width of the format specifier. Text is left-justified, with enough spaces after it to exactly fill the width specifier.

|     99.50| (10 wide, 2 after the decimal)
|Hello | (10 wide, text)
|04/07/1997| (#days as a date)
|01:49:28 PM|
|394,363,201.00| (14 wide, number with thousands separator)
|394.363.201,00| (14 wide, number with European thousands separator)
|007| (3 wide, integer part of number only, zeroes preceding)

Given a number 345.67, the following format specifiers will display as shown:
8.3f = | 345.670| (f stands for floating point)
8.2f = | 345.67|
8.1f = | 345.7| (notice rounding from .67 to .7)
8.0f = | 346| (notice rounding from .67 to next higher integer)
.5d = |00345| (notice no rounding, and preceding 0s to fill 5 digits)

Optional date format -- to format a number as a date (the number must represent the number of days since Midnight, January 1st, 0000), use the optional date specifier and a date format, the same as from the [date] tag. Also see date and time [math].

It is always advised to [format] your math operations as WebDNA is working on a deep fractional part of the number, rounded by the server processor, which can sometimes yield strange results: instead of getting a "0", you might obtain a 0.0000000000000001

To specify the precision of a number, we must use like [format .2f][math]25*34.567[/math][/format]. From version 8.6, you can use [math .2f]25*34.567[/math]

WebDNA Team


Top Articles:

WebDNA Libraries

A list of available libraries for WebDNA...

Download WebDNA Applications

WebDNA applications...


A compilation of some user's questions...

WebDNA Modules

A list of the currently available modules...

Tips and Tricks

A list of user-submitted tips ...

Technical Change History

This Technical Change History provides a reverse chronological list of WebDNA changes...

Related Readings:




The formulas...


When listing files...


[encrypt] and [decrypt] allow you to store sensitive data in your databases without risk of exposing it to prying eyes...


Lists all the form variables and parameters passed to the current page...


The number displayed is the number of words inside the context...