Created
March 6, 2012 22:24
-
-
Save vcsjones/1989421 to your computer and use it in GitHub Desktop.
Parsing different DateTime formats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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