Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Excel VBA splitting a string into a Date

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading