+ Reply to Thread
Results 1 to 11 of 11

Extract date and time from a string

  1. #1
    Forum Contributor
    Join Date
    07-29-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    365
    Posts
    255

    Extract date and time from a string

    I have this data & would like to extract the date in dd/mm/yy and the time stamp separately to use in some calcs.

    Jan 10, 2014 4:47 AM
    Jan 10, 2014 4:47 AM
    Jan 14, 2014 4:30 PM
    Jan 15, 2014 4:00 PM
    Jan 16, 2014 5:01 PM

    MQ
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,733

    Re: Extract date and time from a string

    Are those text values, or date/times formatted to look like that?

    Pete

  3. #3
    Forum Contributor
    Join Date
    07-29-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    365
    Posts
    255

    Re: Extract date and time from a string

    They are General, when I chage to date format it stays the same.

    This data came out of a CISCO telephany system

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Extract date and time from a string

    as long as jan 01 is jan 01 not jan 1
    simply =DATEVALUE(MID(A1,5,2)&LEFT(A1,3)&MID(A1,9,4)) for date and
    =TRIM(RIGHT(A1,8))+0 cell format as h:mm am/pm for time
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,733

    Re: Extract date and time from a string

    They are text values, then. Assuming the first is in cell A1, put this formula in B1:

    =DATE(MID(A1,9,4),MATCH(LEFT(A1,3),{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},0),MID(A1,FIND(",",A1)-2,2))

    Format as a date in the style you prefer, then copy down. Put this formula in C1:

    =--(MID(A1,FIND(" ",A1,12)+1,5)&":00")+IF(ISNUMBER(FIND("PM",A1)),0.5)

    Format that as a time in your preferred style, then copy down.

    Hope this helps.

    Pete

  6. #6
    Forum Contributor
    Join Date
    07-29-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    365
    Posts
    255

    Re: Extract date and time from a string

    Quote Originally Posted by martindwilson View Post
    as long as jan 01 is jan 01 not jan 1
    simply =DATEVALUE(MID(A1,5,2)&LEFT(A1,3)&MID(A1,9,4)) for date and
    =TRIM(RIGHT(A1,8))+0 cell format as h:mm am/pm for time
    Thanks heaps, that worked nicely..

    Hmmm, I have noticed that dates each month before the 10th do return a #VALUE!, do you know a work around?

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,733

    Re: Extract date and time from a string

    Try mine ...

    Pete

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Extract date and time from a string

    that would be
    =DATEVALUE(TRIM(MID(A1,FIND(",",A1)-2,2))&LEFT(A1,3)&MID(A1,FIND(",",A1)+2,4))

  9. #9
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Extract date and time from a string

    This should work for any date

    =SUBSTITUTE(MID(A1,5,8),",",LEFT(A1,3))+0

    format in required date format
    Audere est facere

  10. #10
    Forum Contributor
    Join Date
    07-29-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    365
    Posts
    255

    Re: Extract date and time from a string

    Quote Originally Posted by Pete_UK View Post
    Try mine ...

    Pete
    Same thing happened with your solution Pete!

  11. #11
    Forum Contributor
    Join Date
    07-29-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    365
    Posts
    255

    Re: Extract date and time from a string

    Quote Originally Posted by daddylonglegs View Post
    This should work for any date

    =SUBSTITUTE(MID(A1,5,8),",",LEFT(A1,3))+0

    format in required date format
    This one worked really well.

+ 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] Extract a date from a string
    By DavidNO in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 12-19-2013, 05:55 PM
  2. [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
  3. Extract date from string
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-01-2011, 08:39 AM
  4. Extract the time from a text string
    By knighttrader in forum Excel General
    Replies: 5
    Last Post: 07-27-2008, 01:52 PM
  5. extract date from string
    By kdp145 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-03-2006, 10:54 AM

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