Public Function ConvertoDate(ByVal dateString As String, ByRef result As DateTime) As DateTime Try Dim supportedFormats() As String = New String() {"dd/MM/yyyy", "MM/dd/yyyy", "MM/dd/yy", "ddMMMyyyy", "dMMMyyyy"} result = DateTime.ParseExact(dateString, supportedFormats, System.Globalization.CultureInfo. CurrentCulture, System.Globalization.DateTimeStyles.None) Return result Catch ex As Exception Return Nothing End Try End FunctionWe should enter the Date below format. Then only it will convert into DateTime. Dim supportedFormats() As String = New String() {"dd/MM/yyyy", "MM/dd/yyyy", "MM/dd/yy", "ddMMMyyyy", "dMMMyyyy"} Calling the function
ConvertoDate(frmDate, TfrmDate)
frmDate - String
TfrmDate - DateTime object
Monday, December 14, 2009
How to convert the string to DateTime ?
Common Function:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment