Friday, March 02, 2007

2. Date formatting in vb .net*

Friday, March 02, 2007 10:55:27 PM (GMT Standard Time, UTC+00:00)

It's been an issue with me for a wHILE - when I'm looking to do formatting of dates in vb.NET, I always get lost and waste time! Well I've found a site that's GREAT for information.

The site from Macon State College - here it is.

To be honest, that site has functionality in its raw form as relies on the Microsoft.VisualBasic namespace (DLL), a now outdated namespace. So, even though I support that site I think you should more use the following formats when dealing with dates...

Assume you wanted to format #12/30/07# from that dirty US date format... (Also assume "aDate = #12/30/2007#"), you'd do the following:

aDate.ToString("dd-MMM-yyyy") 'which would give 30-Dec-2007 as a nice string.

And what if you wanted to format times?

Now.ToString("dd-MMM-yyyy hh:mm:ss tt") 'gives 02-Mar-2007 06:45:15 PM

There you'd recognise that the "tt" gives AM or PM, which ever is relevant. Rather cool instead of using any 24 hour format!

Anyway, enough on that for now but definitely check that site, I'm using this blog post as a Bookmark to it also! :)

Related posts:
Select a random row in MS SQL...
Regular expressions
VS2005, ASP.NET 2 & DLLs, DLLs..
MS's ASP.NET and.. PHP
2-way databinding cascading drop down lists within a FormView
ApplicationName Property when customising providers

Comments are closed.