Sub ParseAnyDate (strDateTime As String) As Long
Dim CurrentFormat As String = DateTime.DateFormat
Dim Format As String = DetermineDateFormat(strDateTime)
Log(Format)
DateTime.DateFormat = Format
Dim LongDate As Long = DateTime.DateParse(strDateTime)
DateTime.DateFormat = CurrentFormat
Return LongDate
End Sub
Sub DATE_FORMAT_REGEXPS As Map
Dim Map1 As Map
Map1.Initialize
Map1.Put("(\d\d\d\d\d\d\d\d)", "yyyyMMdd")
Map1.Put("(\d\d\d\d\d\d\d\d\d\d\d\d)", "yyyyMMddHHmm")
Map1.Put("(\d\d\d\d\d\d\d\d\d\d\d\d\d\d)", "yyyyMMddHHmmss")
Map1.Put("(\d\d\d\d\d\d\d\d)\s(\d\d\d\d)", "yyyyMMdd HHmm")
Map1.Put("(\d\d\d\d\d\d\d\d)\s(\d\d\d\d\d\d)", "yyyyMMdd HHmmss")
Map1.Put("(\d\d)/(\d\d)/(\d\d\d\d)", "dd/MM/yyyy")
Map1.Put("(\d\d)-(\d\d)-(\d\d\d\d)", "dd-MM-yyyy")
Map1.Put("(\d\d\d\d)/(\d\d)/(\d\d)", "yyyy/MM/dd")
Map1.Put("(\d\d\d\d)-(\d\d)-(\d\d)", "yyyy-MM-dd")
Map1.Put("(\d\d)\s[a-zA-Z]{3}\s(\d\d\d\d)", "dd MMM yyyy")
Map1.Put("(\d\d)\s(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d\d\d)", "dd MMMM yyyy")
Map1.Put("(\d\d)/(\d\d)/(\d\d\d\d)\s(\d\d):(\d\d)", "dd/MM/yyyy HH:mm")
Map1.Put("(\d\d)-(\d\d)-(\d\d\d\d)\s(\d\d):(\d\d)", "dd-MM-yyyy HH:mm")
Map1.Put("(\d\d\d\d)/(\d\d)/(\d\d)\s(\d\d):(\d\d)", "yyyy/MM/dd HH:mm")
Map1.Put("(\d\d\d\d)-(\d\d)-(\d\d)\s(\d\d):(\d\d)", "yyyy-MM-dd HH:mm")
Map1.Put("(\d\d)\s[a-zA-Z]{3}\s(\d\d\d\d)\s(\d\d):(\d\d)", "dd MMM yyyy HH:mm")
Map1.Put("(\d\d)\s(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d\d\d)\s(\d\d):(\d\d)", "dd MMMM yyyy HH:mm")
Map1.Put("(\d\d)/(\d\d)/(\d\d\d\d)\s(\d\d):(\d\d):(\d\d)", "dd/MM/yyyy HH:mm:ss")
Map1.Put("(\d\d)-(\d\d)-(\d\d\d\d)\s(\d\d):(\d\d):(\d\d)", "dd-MM-yyyy HH:mm:ss")
Map1.Put("(\d\d\d\d)/(\d\d)/(\d\d)\s(\d\d):(\d\d):(\d\d)", "yyyy/MM/dd HH:mm:ss")
Map1.Put("(\d\d\d\d)-(\d\d)-(\d\d)\s(\d\d):(\d\d):(\d\d)", "yyyy-MM-dd HH:mm:ss")
Map1.Put("(\d\d)\s[a-zA-Z]{3}\s(\d\d\d\d)\s(\d\d):(\d\d):(\d\d)", "dd MMM yyyy HH:mm:ss")
Map1.Put("(\d\d)\s(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d\d\d)\s(\d\d):(\d\d):(\d\d)", "dd MMMM yyyy HH:mm:ss")
Return Map1
End Sub
Sub DetermineDateFormat (dateString As String) As String
For Each pattern In DATE_FORMAT_REGEXPS.Keys
If Regex.IsMatch(pattern, dateString) Then Return DATE_FORMAT_REGEXPS.Get(pattern)
Next
Return Null
End Sub