How to Convert String to Date Format

To Convert String To Date Format, use the DateTime.ParseExact function

DateTime.ParseExact(s as String, format as String, provider As IFormatProvider) as DateTime

Parameters:

s
Type: System.String
A string that contains a date and time to convert. 
format
Type: System.String
A format specifier that defines the required format of s
provider
Type: System.IFormatProvider
An object that supplies culture-specific format information about s

Example:
 

  1.     Private Function ToDate() As DateTime
  2.  
  3.         Dim str As String = "20060505"
  4.  
  5.         Dim mDate As DateTime
  6.  
  7.  
  8.  
  9.         mDate = DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat)
  10.  
  11.         Return mDate
  12.  
  13.     End Function

Read More about DateTime.ParseExact Method (String, String, IFormatProvider)

,

  1. No comments yet.
(will not be published)
Submit Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Subscribe to comments feed
  1. No trackbacks yet.

SetPageWidth