I didn't post this originally, because I felt it didn't address the root of the problem, however, if you want a workaround, you can use the below function in a similar way as you would use a CDate
, by calling ConDate("12/12/2016")
.
This is is the way I approached the problem:
Sub MainTest()
Dim InputString As String, OutputDate As Date
InputString = "01/12/2016"
OutputDate = ConDate(InputString)
Debug.Print OutputDate, TypeName(OutputDate)
End Sub
Function ConDate(ByRef InputString As String) As Date
Dim Day As Long, Month As Long, year As Long
'mmddyyyy format
Month = CLng(Left(InputString, InStr(1, InputString, "/", vbTextCompare) - 1))
Day = CLng(Mid(InputString, InStr(1, InputString, "/", vbTextCompare) + 1, InStrRev(InputString, "/", , vbTextCompare) - InStr(1, InputString, "/", vbTextCompare) - 1))
year = CLng(Right(InputString, 4))
ConDate = DateSerial(year, Month, Day)
End Function
Not wanting to plagerise sebifeixler's answer I kept my original left/mid/right to separate the day/month/year, but I feel it's much neater to use his split function to separate the date by "/". A combination of the two would be a good workaround.