GeekArticles
Database
SQL Server
Database
SQL ServerFormatting Dates, Times and Numbers in ASP.NET
<p><i>Formatting</i> is the process of converting a variable from its native type into a string representation. Anytime you display a <code>DateTime</code> or numeric
variables in an ASP.NET page, you are formatting that variable from its native type into some sort of string representation. How a <code>DateTime</code> or numeric
variable is formatted depends on the culture settings and the format string. Because dates and numeric values are formatted differently across cultures, the .NET
Framework bases its formatting on the specified culture settings. By default, the formatting routines use the culture settings defined on the web server, but you can
indicate that a particular culture be used anytime you format. In addition to the culture settings, formatting is also affected by a format string, which
spells out the formatting details to apply.
</p><p>
The .NET Framework contains a bounty of format strings. There are <i>standard format strings</i>, which are typically a single letter that applies detailed formatting
logic. For example, the format specifier will format a numeric type as a currency value; the format specifier displays the month name and four-digit year of
the specified <code>DateTime</code> value. There are also <i>custom format strings</i>, which display a apply a very specific formatting rule. These custom format
strings can be put together to build more intricate formats. For instance, the format string MMMM displays the full day of the week name followed by a comma
followed by the full name of the month followed by the day of the month. For more involved formatting scenarios, where neither the standard or custom format strings
cut the mustard, you can always create your own formatting <a methods</a>.
</p><p>
This article explores the standard format strings for dates, times and numbers and includes a number of custom formatting methods created and use in my own
projects. also a demo application you can download that lets you specify a culture and then shows you the output for the standard format strings for the
selected culture. Read on to learn more!
<br /><a More ></a></p>
Sponsored Links
Related Topics
Subscribe via RSS
SQL Server
- Naming Database Objects: Part II
- Trace Messages Part V: Trace Cleanup
- Naming Database Objects: Part I
- Multiple-Child Aggregation
- Creating SQL Tables for an Integrating Application Using Dexterity
- SQL Server 2005 Beta 2 Transact-SQL Enhancements
- .NET Rocks! - Brian Larson on SQL Server Reporting Services
- Computing the Trimmed Mean in SQL
- SQL Server 2000 Gains on Oracle
- Separator First Formatting (SFF)
