I have a string that I want to split into the format MM/DD/YYYY. Example: "TIME_STAMP : Mon Jul 22 15:45:43 2024" will need to be split and the result should be "7/22/2024" if possible, but if just as a string "Jul 22 2024" works as well. Below is a code I found online, but can’t seem to work.
Function ReturnNthElement(CellRef As Range, ElementNumber As Integer)
Dim Result() As String
Result = Split(CellRef, ",")
ReturnNthElement = Result(ElementNumber - 1)
End Function
>Solution :
You can use this method:
Dim TextTime As String
Dim TrueDate As Date
TextTime = "TIME_STAMP : Mon Jul 22 15:45:43 2024"
TrueDate = DateValue(Right(TextTime, 4) & Mid(TextTime, 17, 7))