Developers blog, .NET, C#, VB.NET, ATLAS, AJAX, WWF, ORM, LINQ, ARCHITECTURE and more by Frank Kroondijk
dinsdag, april 18, 2006
Stop Using DatePart for Formatting Dates!
If you're still formatting dates as such:
lblDate.text = datepart("d",Now) & "/" & datepartt("m",now) & "/" & datepart("yyyy",now)
then stop this instant! Step away from the keyboard and no one gets hurt.
There are better ways in ASP.NET to format dates. You could replace the above line of code with:
lblDate.text = getdate().tostring("MM/dd/yyyy")
and end up with exactly what you needed. ASP.NET is full of great format strings. Remmeber the old FormatCurrency(MyCash) command? You can replace that with MyCash.ToString("C"). Download the .NET 2.0 SDK and look up "formatting strings"; you'll find all these goodies in there.
by Richard Dudley