+ Reply to Thread
Results 1 to 15 of 15

Date and time parsing from text string

  1. #1
    Registered User
    Join Date
    09-23-2013
    Location
    Germany
    MS-Off Ver
    365
    Posts
    14

    Date and time parsing from text string

    Hi everybody,
    I have read plenty of entries and other threads but I cannot get the required result. Hence, I am hoping that you might be able to assist me.
    Here is the problem statement:
    - I have a text field which has no defined pattern and I need to extract dates and times, if possible
    - The text field can contain two dates or two times, but not both
    - Neither information is at a fixed location within the text field
    - The formatting of the dates can vary. There might be other instances of the dash "-" in the cell and thus, it cannot be used as a differentiator
    • "dd.mm.yy" - "dd.mm.yy"
    • "dd.mm.yy - dd.mm.yyyy"
    • "dd.mm.yyyy - dd.mm.yy"
    • "dd.mm.yyyy - dd.mm.yyyy"
    - The times are in in a uniform 24h format. It appears that the colon ":" is used only in combination with date fields, but similar to the date field, the dash "-" has multiple occurences within the same cell.
    • "mm:hh - mm:hh"

    Preferrably the results should be in a format such as:
    Date start | Date end | Time start | Time end

    I tried to search for a character pattern and start extracting from there, but it seems this exceeds my Excel horizon by miles.

    I am gratful for any assitance I can get.

    Thanks very much in advance.
    Max

  2. #2
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Date and time parsing from text string

    Hi

    For date start and date end use
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    For time use
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by José Augusto; 06-11-2019 at 11:24 AM. Reason: Add a file

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Date and time parsing from text string

    Max

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED, scroll down and click Manage Attachments.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    09-23-2013
    Location
    Germany
    MS-Off Ver
    365
    Posts
    14

    Re: Date and time parsing from text string

    Hi Norie,
    thanks for your respose. I attached a sample file hereto which I hope shows my intentions.
    The data originates from a freetext field in a database. So the patterns where the dates might be will be pretty random.

    Best regards
    Max
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    09-23-2013
    Location
    Germany
    MS-Off Ver
    365
    Posts
    14

    Re: Date and time parsing from text string

    Hi José,
    thanks very much for your prompt response. Unfortunately, the date and time information is embedded in a random text string.

    Best regards
    Max

  6. #6
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Date and time parsing from text string

    Hi

    My first approach
    Try in D2, E2, F2 and G2
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Last row has no equal sign and gives a error . I try another alternative

  7. #7
    Registered User
    Join Date
    09-23-2013
    Location
    Germany
    MS-Off Ver
    365
    Posts
    14

    Re: Date and time parsing from text string

    Hi José,
    thanks again ! This looks pretty good.
    The cell might have entries such as:

    "Service Asset 1 & Asset 2 <br />Duration 20.01.2019 - 24.01.2019"

    So, yes, there might not be a "=" sign indicating that there might be a date field. Initially I was hoping to be able to parse the cell for a text string ??.??.???? and extract therefrom, but I did not get very far with it ...

    Max

  8. #8
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Date and time parsing from text string

    Hi

    A more robust search date in string In D2, E2. F2 and G2 are the same.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Note: I use Columns($A$1:$CX$1) which means a search in a string of length 112 (102+10) char. If your string are longer than that use a greater column such as $ZZ$1 (702+10).

    See the file
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    09-23-2013
    Location
    Germany
    MS-Off Ver
    365
    Posts
    14

    Re: Date and time parsing from text string

    Hi José,
    great, thank you very much thus far. I am not able to test it right now on the real dataset, but will do so tomorrow and update you as soon as possible.
    Thanks again for your efforts.

    Regards
    Max

  10. #10
    Registered User
    Join Date
    09-23-2013
    Location
    Germany
    MS-Off Ver
    365
    Posts
    14

    Re: Date and time parsing from text string

    Hi José,
    I tested your solution and it works partially. The file holds various formats of times and dates.
    Is there a way to look for a pattern in the cell, such as "??.??.??". Maybe that can be an approach rather than relating it to certain characters within the cell ?

    Thanks
    Max

  11. #11
    Registered User
    Join Date
    09-23-2013
    Location
    Germany
    MS-Off Ver
    365
    Posts
    14

    Re: Date and time parsing from text string

    Hi José,
    I re-worked some of the formulas and got a good result to extract the times, but the problem remains with the dates.
    Here are some sample entries where your approach does not work. I suppose it is because of the missing CHAR(160).
    • Asset 1 Standby<br />Service date/time 05.10.15 00:00 - 06.10.15 06:00
    • Service date 23.03.2015 - 27.03.2015
    • Asset 1<br />Location 2<br />Service date 05.05.2016 - 06.05.2016

    In summary, the formula would need to work for the following date formats:
    • [dd.mm.yy - dd.mm.yy]
    • [dd.mm.yy - dd.mm.yyyy]
    • [dd.mm.yyyy - dd.mm.yy]
    • [dd.mm.yyyy - dd.mm.yyyy]
    • [dd.mm.yy hh:mm - dd.mm.yy hh:mm]

    I tried to serach for pattern, i.e. SEARCH("??.??.??"; ....) but that got me too many mixed results. It would helo, if I were able to do this =SEARCH("##.##.##"; ...), but I understood from other threads looking for numbers patterns with SEARCH is not possible.

    Any chance you have another approach ?

    Thanks
    Max

  12. #12
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Date and time parsing from text string

    Try this 4 formulas

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    See the file
    Attached Files Attached Files

  13. #13
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Date and time parsing from text string

    Hi @MaximH

    In my attempts I try to use the SEARCH function in the bad way, with {10,8} array.

    Now, I get the same results with this two formulas for dates
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    09-23-2013
    Location
    Germany
    MS-Off Ver
    365
    Posts
    14

    Re: Date and time parsing from text string

    Thank you very much José.
    That did the trick. I had to correct a few entried manually, but that was due mainly to the quality of entry, rather than the formula.

    Thanks again for your expertise in this case !

    Best regards
    Max

  15. #15
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Date and time parsing from text string

    You are welcome and thanks for the feed-back. I'm happy to have helped.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Parsing text at different points from a string
    By vpan in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-23-2017, 03:19 PM
  2. [SOLVED] Parsing out Sizes/Colors from text string
    By BlakeSkate in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 07-15-2015, 02:19 PM
  3. [SOLVED] Extract time from date and time text string
    By pattem2013 in forum Excel General
    Replies: 5
    Last Post: 09-07-2013, 03:20 AM
  4. Parsing out text in a string
    By VegasL in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-22-2013, 02:35 PM
  5. Need to capture date data in a text string containing a date and time stamp
    By Grilleman in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-07-2013, 01:14 PM
  6. Parsing a Date to a Specific String Value
    By Mordred in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-08-2010, 02:57 PM
  7. Text parsing, find string after : character
    By proepert in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-14-2010, 10:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1