ASP.Net VB Format Date Using ToString Function

by top54u.com 22 Jul, 2008

ASP.Net VB Format Date according to your requirement can be customized using ToString function. You can pass the format of Date to VB ToString function to display the Date in the specified format. There are alphabetical symbols to represent the formats for Date parts such as M for month, d for day and y for year. You can adjust the sequence of Date parts using these terms to format Date. Following are different types of ASP.Net VB format Date patterns that can be used in Asp.Net web pages to display the date:

 

  • MM/dd/yyyy

  • MM-dd-yyyy

  • dd-MM-yyyy

  • dd/MM/yyyy

  • dddd, MMM dd, yyyy

  • MMM dd, yyyy

  • MMMM dd, yyyy

 

Above Date Formats can be used to display the Date in different ways.

 

Syntax for ASP.Net VB Format Date using ToString Function

 

You can pass the above discussed Date Formats to the ToString function:

DateTime.Now.ToString("MM/dd/yyyy")

 

Similarly you can pass different format combinations for Date.

 

Examples of ASP.Net VB Format Date using ToString Function

 

' Displays short date format MM/dd/yyyy

Response.Write(DateTime.Now.ToString("MM/dd/yyyy"))

Response.Write("<br>")

 

' Displays short date format MM-dd-yyyy

Response.Write(DateTime.Now.ToString("MM-dd-yyyy"))

Response.Write("<br>")

 

' Displays short date format dd-MM-yyyy

Response.Write(DateTime.Now.ToString("dd-MM-yyyy"))

Response.Write("<br>")

 

' Displays short date format dd/MM/yyyy

Response.Write(DateTime.Now.ToString("dd/MM/yyyy"))

Response.Write("<br>")

 

' Displays long date format MMM dd, yyyy

' MMM shows first three letters of month name

Response.Write(DateTime.Now.ToString("MMM dd, yyyy"))

Response.Write("<br>")

 

' Displays long date format dddd, MMM dd, yyyy

' dddd shows full name of the day

Response.Write(DateTime.Now.ToString("dddd, MMM dd, yyyy"))

Response.Write("<br>")

 

' Displays date format MMMM dd, yyyy

' MMMM shows full name of the month

Response.Write(DateTime.Now.ToString("MMMM dd, yyyy"))

 

Output:

07/22/2008
07-22-2008
22-07-2008
22/07/2008
Jul 22, 2008
Tuesday, Jul 22, 2008
July 22, 2008

Spotlight.....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , , , , , , , ,

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

10/11/2008 3:39:09 AM




related videos.....
recent posts.....
top54u ezines.....