ASP.Net VB DateTime Parse Function

by top54u.com 17 Jul, 2008
Spotlight.....

ASP.Net VB DateTime Parse Function also provides the functionality to convert the string to DateTime as we discussed in the previous article about ASP.Net Convert String to DateTime using ToString Function. While using the DateTime parse function in ASP.Net VB code you have to use IFormatProvider Interface to pass the information about the current or desired Culture. IFormatProvider enables you to parse the DateTime string to different Cultures and Format Date into that Culture with different styles.

 

Syntax for IFormatProvider for Different Cultures

 

Dim Culture As IFormatProvider

' For GB Culture Pass en-GB

Culture = New CultureInfo("en-GB", True)

 

' For French Culture Pass fr-Fr

Culture = New CultureInfo("fr-Fr", True)

 

Both cultures mentioned above accept the different DateTime Formats.

If you are using DateTime.Parse then you have to pass the MM/dd/yyyy hh:mm:ss Format of DateTime for French culture and dd/MM/yyyy hh:mm:ss for US English culture. You have to check the format for different cultures by changing the position of month and day.

 

Example for ASP.Net VB DateTime Parse Function

 

Dim myDateTimeString As String

myDateTimeString = "22/07/2008"

 

Dim dt As DateTime

Dim Culture As IFormatProvider

 

' For GB Culture Pass en-GB

' coz date string is in dd/MM/yyyy

Culture = New CultureInfo("en-GB", True)

 

dt = DateTime.Parse(myDateTimeString, Culture, DateTimeStyles.NoCurrentDateDefault)

 

 

Response.Write(dt.Day & "/" & dt.Month & "/" & dt.Year)

 

Response.Write("<br>")

 

Response.Write(dt.ToString("dddd"))

 

Response.Write("<br>")

 

Response.Write(dt.ToString("MMMM"))

 

Output:

22/7/2008
Tuesday
July

Note: To use CultureInfo import System.Globalization namespace.

Add comment


(Will show your Gravatar icon)  

  Country flag

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



Live preview

8/23/2008 8:43:22 PM

OUR SPONSORS[+ advertise here]
related videos.....
recent posts.....
top54u ezines.....