Skip to content

Instantly share code, notes, and snippets.

@vcsjones
Created March 6, 2012 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vcsjones/1989421 to your computer and use it in GitHub Desktop.
Save vcsjones/1989421 to your computer and use it in GitHub Desktop.
Parsing different DateTime formats
'Make sure this import is at the top of the file:
Imports System.Globalization
'And the actual code:
Public Function ParseDateTime(ByVal dateTimeString As String) As DateTime?
Dim dt As DateTime
'Try to parse the date time...
If DateTime.TryParseExact(dateTimeString, New String() {"yyyyMMdd", "yyyy-MM-dd"}, CultureInfo.CurrentCulture, DateTimeStyles.None, dt) Then
'Parse succeeded!
Return dt
Else
'Parse didn't succeed. Return Nothing...
Return Nothing
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment