ASP.Net Convert String to DateTime Using VB

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

In ASP.Net to convert string into DateTime you can use Convert.ToDateTime function in VB. Further you can also format the output of Date or Time according to your requirement, using different VB Format Date patterns such as MM/dd/yyyy, dd-mm-yyyy etc.

First of all create a string variable to store the string type DateTime.

 

Dim myDateTimeString As String

 

Then create a new variable of type DateTime and pass the string to DateTime variable using Convert.ToDateTime function.

 

Dim dt As DateTime

dt = Convert.ToDateTime(myDateTimeString)

 

Convert.ToDateTime function accepts the string value and returns the Date Type value.

Now you are ready to get the different parts of the Date String passed to the DateTime variable.

 

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

 

Example of ASP.Net Convert String to DateTime Using VB

 

Dim myDateTimeString As String

myDateTimeString = "22 Jul,2008"

 

Dim dt As DateTime

dt = Convert.ToDateTime(myDateTimeString)

 

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

 

Further you can format the DateTime using ToString("xxxxxxxxxx").

Click here to learn ASP.Net VB Format DateTime using ToString Function

Comments

7/19/2008 10:07:57 PM

eldhose

thanks....

eldhose us

Add comment


(Will show your Gravatar icon)  

  Country flag

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



Live preview

8/23/2008 8:40:39 PM

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