Nigel Whitworth's Development Site

You are currently not logged in.

How do I format a date in VB.NET?

In VB6, if you wanted to format a date, all you needed to do was use the FORMAT command. That command now no longer exists. In its place is a method of the date data type called ToString which has an optional parameter. If you pass the format into the parameter, the desired result will be returned. For example if you want the current date displayed as dd/MMMM/yyyy (e.g. 02/April/2006) you would do the following.

     Now.date.ToString("dd/MMMM/yyyy")

Note that MM is different from mm which is minutes not months. Below details the different formatting codes that can be used.

CodeDescription
dThe day of the month without preceeding 0 if before the 10th.
ddDay of the month, if before 10, then return with preceeding 0
dddDay of the week abbreviated e.g. Mon, Tues
ddddFull name of the day of the week e.g. Monday, Tuesday
MMonth of the year without preceeding 0 if before 10th Month
MMMonth of the year with preceeding 0 if before the 10th Month
MMMMonth of the year abbreviated in words, e.g. Jan, Feb
MMMMThe full name for the month of the year, e.g. January, February
yYear in two digits without a preceeding 0 if before the 10th year of a century.
yyYear in two digits with a preceeding 0 if before the 10th year of a century
yyyyFull year in four digits, e.g. 2006
ggEra/Period the date is in, e.g. A.D.



If you intend to vote or make a comment, please enter the security code.

Make a comment

*Comments are the views of individuals, they may or may not be correct.
All comments are reviewed and accepted or rejected.
If you give an email address, you will be sent an email when someone makes a comment on this page.*

Name :
Email :
Comments :


Only name and Code is compulsory.
 
 
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)