I have datetime stamp (MMDDYYYYHHMMSS) extracted from a file Name as
Filedate = "10212015140108"
How can I convert it into datetime format mm/dd/yyyy hh:mm:ss.
Can someone help to get it resolved?
From what I can gather from the question it looks as though the Filedate value is just a string representation of date (mmddyyyyhhnnss), with that in mind did a quick test to see if I could parse it into the format required.
There are other ways of approaching this like using a RegExp object to build up a list of matches then use those to build the output.
Worth noting that this example will only work if the structured string is always in the same order and the same number of characters.
Function ParseTimeStamp(ts)
Dim df(5), bk, ds, i
'Holds the map to show how the string breaks down, each element
'is the length of the given part of the timestamp.
bk = Array(2,2,4,2,2,2)
pos = 1
For i = 0 To UBound(bk)
df(i) = Mid(ts, pos, bk(i))
pos = pos + bk(i)
Next
'Once we have all the parts stitch them back together.
'Use the mm/dd/yyyy hh:nn:ss format
ds = df(0) & "/" & df(1) & "/" & df(2) & " " & df(3) & ":" & df(4) & ":" & df(5)
ParseTimeStamp = ds
End Function
Dim Filedate, parsedDate
Filedate = "10212015140108"
parsedDate = ParseTimeStamp(FileDate)
WScript.Echo parsedDate
Output:
10/21/2015 14:01:08
mmddyyyyhhnnss(21 Oct 2015 14:01:08)