Convert String to Excel date and time with a specific string format

I have an Excel / VBA macro that lists files in a directory.

File names are in the format: yyyy-MM-dd @ hh-mm-ss_ [description] .csv

for example: 2013-07-03@22-43-19 _my-file.csv

Then I need to transfer the first part of the file name to the Excel Date object (including timestamp)

I found the CDate () function, but it does not accept any "format" parameter, and the Format () function does not work that way, for converting String to Date.

I would like to get a function with accepts String and format and returns an Excel Date / Time object.

Is there a feature designed for this?

Thanks,

+4
source share
1 answer

Try the following:

 Function ParseDateTime(dt As String) As Date ParseDateTime = DateValue(Left(dt, 10)) + TimeValue(Replace(Mid(dt, 12, 8), "-", ":")) End Function 
+3
source

Source: https://habr.com/ru/post/1489585/


All Articles