0

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?

7
  • So you have an existing VBScript and it has a variable called Filedate which contains 10212015140108 ? Post your code and also explain the rules on how this number could be converted. Commented Oct 22, 2015 at 11:01
  • Ideally you should post your workings so far, if you expect to be helped. Commented Oct 22, 2015 at 11:50
  • @Nick.McDermaid I think the format is fairly obvious if you look at it close enough - mmddyyyyhhnnss (21 Oct 2015 14:01:08) Commented Oct 22, 2015 at 12:04
  • 1
    To someone from Australia it's not immediately obvious (our data format is d - m - y). To expedite an answer its in your interests to specify these things straight up. PS you still haven't posted your code. Commented Oct 22, 2015 at 23:20
  • 1
    @Nick.McDermaid I'm from the UK but have worked with various date formats for years. OP should still be posting some code to show the context of the question. Commented Oct 23, 2015 at 7:09

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.