Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Park City, Utah
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Parsing a Variable (Word 2003 VBA)

    I have the following date in a document which is copied into a variable and placed in another document:

    Tue Feb 01 17:24:58 2005

    I need to parse this into the following date format:

    yyyymmddhhmmss, so the above date/time would appear as:

    20050201172458

    I can do it by character-based manipulations and an If statement changing the month abbreviation to its corresponding number, but I would like to do it in the variable(s) contents or whichever is more efficient/easier.

    Any ideas?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Parsing a Variable (Word 2003 VBA)

    Here is a way using only one string variable:

    Dim strTest As String
    strTest = "Tue Feb 01 17:24:58 2005"
    strTest = Mid(strTest, 9, 2) & "-" & Mid(strTest, 5, 3) & "-" & Right(strTest, 4) & Mid(strTest, 11, 9)
    strTest = Format(CDate(strTest), "yyyymmddhhmmss")

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Parsing a Variable (Word 2003 VBA)

    > I have the following date

    This appears as a special case of generalised string parsing: dates.

    I have had success using a built-in parser called DateValue<pre> Public Function blnDateStringIsValid(strIn As String) As Boolean
    blnDateStringIsValid = False
    On Error GoTo Failed
    Dim dt As Date
    dt = DateValue(strIn)
    blnDateStringIsValid = True
    Exit Function
    Failed:
    End Function</pre>


  4. #4
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Park City, Utah
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Parsing a Variable (Word 2003 VBA)

    Once again, thank you! I knew there was a way to do that, I just haven't used the Mid function for so long, forgot what it was called.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •