+ Reply to Thread
Results 1 to 18 of 18

Extract a date from a string

  1. #1
    Registered User
    Join Date
    12-08-2013
    Location
    Abertillery
    MS-Off Ver
    Excel 2007,2010
    Posts
    17

    Extract a date from a string

    Hi Members

    I have no real idea where to start on this one, i have data in a column eg Column "B2" as 16/12/13 AA 09.30, i would like to be able to extract the date portion and put in cell "C2", and put the time portion in "D2". The only part that could change would be the middle text which could be 16/12/13 ANG 09.30 or a different three characters but no more than three.
    I hope this makes sense and someone is able to help.

    Many Thanks
    David

  2. #2
    Registered User
    Join Date
    01-16-2013
    Location
    Oklahoma City, OK
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Extract a date from a string

    Try this:

    =LEFT(CELL,8) and in a new cell =RIGHT(CELL,4) That should pull the date out into two separate cells

  3. #3
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Extract a date from a string

    In C2

    =TRIM(LEFT(SUBSTITUTE(B2," ",REPT(" ",255)),255))

    In D2

    =TRIM(RIGHT(SUBSTITUTE(B2," ",REPT(" ",255)),255))

    B
    C
    D
    1
    2
    16/12/13 AA 09.30 16/12/13 09.30
    3
    4
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Extract a date from a string

    You are using the UK date format, so this should work for you. For the date...
    =DATEVALUE(LEFT(B2,8))
    andthen for the time...
    =TIMEVALUE(RIGHT(SUBSTITUTE(B2,".",":"),4))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Extract a date from a string

    With the time in B2 enter this in C2 and format as dd:mm:yyyy

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


    In D2 enter this and format as h:mm

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  6. #6
    Registered User
    Join Date
    12-08-2013
    Location
    Abertillery
    MS-Off Ver
    Excel 2007,2010
    Posts
    17

    Re: Extract a date from a string

    Hi FDibbins
    I followed your code the date value worked but the time comes up with an error yet the calc steps show the time value correctly but the cell shows #value!, I cannot see what is missing?

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Extract a date from a string

    what does your time format look like?

    Try entering just 9:20 in a cell and see what happens?

  8. #8
    Registered User
    Join Date
    12-08-2013
    Location
    Abertillery
    MS-Off Ver
    Excel 2007,2010
    Posts
    17

    Re: Extract a date from a string

    Thank you all for your replies they all work but I now need to work out how to repeat the process in a macro to loop down a column and change each one, I will have a go before asking for help.

    David

  9. #9
    Registered User
    Join Date
    12-08-2013
    Location
    Abertillery
    MS-Off Ver
    Excel 2007,2010
    Posts
    17

    Re: Extract a date from a string

    Yes it works I mistook the : for a . can this code be put in a macro to extract the same data down a column of data with the same structure.

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Extract a date from a string

    VBA isnt my strong side, but Im sure someone can put that together for you

    An alternative would be to put those 2 formulas in their own cells, copy down as far as needed, and then copy/paste values over the formulas to just have the answer - you can then delete (or hide) the original column if needed

  11. #11
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Extract a date from a string

    Try this..

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


    I think.. you can able to Change Range part or Formula to Value, if required.
    Else.. Please let us know..
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  12. #12
    Registered User
    Join Date
    12-08-2013
    Location
    Abertillery
    MS-Off Ver
    Excel 2007,2010
    Posts
    17

    Re: Extract a date from a string

    Hi Debraj Roy
    The first part of your code works, but the second part for the time just puts TEXT(TIMEVALUE(SUBSTITUTE(MID(F2,SEARCH("??.??",F2),5),".",":")),"hh:mm") in every cell down the column? any thoughts please.

  13. #13
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Extract a date from a string

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  14. #14
    Registered User
    Join Date
    12-08-2013
    Location
    Abertillery
    MS-Off Ver
    Excel 2007,2010
    Posts
    17

    Re: Extract a date from a string

    Debraj Roy

    I have attached a file with a before and after sheet hope this helps.

    Cheers
    David
    Attached Files Attached Files

  15. #15
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Extract a date from a string

    Hope that this helps.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    12-08-2013
    Location
    Abertillery
    MS-Off Ver
    Excel 2007,2010
    Posts
    17

    Re: Extract a date from a string

    Thank you that does help but i am now pulling the data into a word document as a mailmerge and the data is in your format rather than the uk format can this be corrected with VBA to format the cells before extracting the data?

  17. #17
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Extract a date from a string

    Quote Originally Posted by DavidNO View Post
    I have attached a file with a before and after sheet hope this helps.
    Did you tried previous code.. !!
    Wait.. before that.. Please change the cell format of Column B & C to General... or (Col B as Date, and Col C as time..

  18. #18
    Registered User
    Join Date
    12-08-2013
    Location
    Abertillery
    MS-Off Ver
    Excel 2007,2010
    Posts
    17

    Re: Extract a date from a string

    Thank you for your help everyone i have it working i had to format the cells as text for it to work correctly.

+ 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. Trying to use DateValue to extract date from string
    By mindtheGaspar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-28-2013, 07:01 PM
  2. [SOLVED] Extract Text from String then Convert to a Date (Month/Year)
    By sgrey24 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-14-2013, 06:11 PM
  3. Extract date from string
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-01-2011, 08:39 AM
  4. problem with len() function to extract date from string
    By ramserp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-24-2009, 10:26 AM
  5. extract date from string
    By kdp145 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-03-2006, 10:54 AM

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