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.
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.
Dim myDateTimeString As String
myDateTimeString = "22/07/2008"
' coz date string is in dd/MM/yyyy
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(dt.ToString("MMMM"))
Output:
22/7/2008 Tuesday July
Note: To use CultureInfo import System.Globalization namespace.
Currently rated 5.0 by 1 people
Tags: asp.net 2.0, asp.net vb datetime parse function, asp.net convert string to date, vb datetime, vb tostring function, asp.net datetime, vb convert string to date, asp.net datetime format, c# datetime, asp.net c# datetime, asp.net vb tostring function, asp.net format date, convert.todatetime function, datetime.parse function, datetime.parseexact function, vb datetime iformatprovider, c# datetime iformatprovider
8/23/2008 8:43:22 PM