+ Reply to Thread
Results 1 to 31 of 31

Extract Date from Text

  1. #1
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Extract Date from Text

    Hi,

    I have a huge data in which Column D has text date starting from D6, I need to extract both the dates within the brackets into column E & G. Sample workbook attached.


    Barieq
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,536

    Re: Extract Date from Text

    See if this works.(working here)
    Please Login or Register  to view this content.

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,037

    Re: Extract Date from Text

    Formula solution - in E6 copied down:

    =IFERROR(VALUE(MID(D6,FIND("|",D6)+2,10)),VALUE(MID(D6,FIND("|",D6)+2,6)&MID(D6,FIND("|",D6)+8,4)+579))

    In F6 copied down:

    =IFERROR(VALUE(MID(D6,FIND("|",D6)+16,10)),VALUE(MID(D6,FIND("|",D6)+16,6)&MID(D6,FIND("|",D6)+22,4)+579))
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,416

    Re: Extract Date from Text

    If the dates always appear at the end of the text with double digit days and months as shown in all your examples, then these two simple formulas can be used...

    E6: =MID(D6,LEN(D6)-26,11)

    F6: =MID(D6,LEN(D6)-11,11)

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,037

    Re: Extract Date from Text

    I think that pulls out text rather than a real date, though, Rick. Correct me if I'm wrong!

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,416

    Re: Extract Date from Text

    Whoops! Thanks Ali (it's almost 4:30 in the morning here and I'm about to go to sleep)... I forgot the 0+...

    E6: =0+MID(D6,LEN(D6)-26,11)

    F6: =0+MID(D6,LEN(D6)-11,11)

    Note: You will have to format each of these cells with the date format of your choice before copying the formulas down.
    Last edited by Rick Rothstein; 03-29-2020 at 04:25 AM.

  7. #7
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,416

    Re: Extract Date from Text

    By the way, if a macro solution is desired and using the same assumptions, we can use the formulas I posted above as a basis...
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-23-2020
    Location
    France
    MS-Off Ver
    2019
    Posts
    44

    Re: Extract Date from Text

    Here is a solution with a VBA macro.

    Before running the macro, define name ListHeader to point to the header above the list of dates.

    The macro first attempts to calculate a Gregorian date. If it fails, it retries with Hijri date.
    Please Login or Register  to view this content.
    HTH,
    --
    LR
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Re: Extract Date from Text

    Thank you all for your code and formula. I really appreciate.

  10. #10
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Re: Extract Date from Text

    @AliGW your formula result is #value
    Last edited by AliGW; 03-29-2020 at 06:34 AM. Reason: Please don't quote unnecessarily!

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,536

    Re: Extract Date from Text

    You are welcome and thanks for the rep.

    Please don't forget to mark the thread as Solved.

  12. #12
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Re: Extract Date from Text

    @ArdusPetus

    I like the code which check the Hijri Date, but some of the rows the date displayed is wrong. Can you please look into this.

    Some Text | 01/11/1440 To 29/10/1441 {04-Jul-2019 To 21-Jun-2020} 9/21/2018 6/20/2020
    Some Text | 01/11/1440 To 29/10/1441 {04-Jul-2019 To 21-Jun-2020} 9/21/2018 6/20/2020
    Some Text | 09/07/1440 To 08/07/1441 {16-Mar-2019 To 03-Mar-2020} 5/11/2019 3/31/2020
    Last edited by AliGW; 03-29-2020 at 06:34 AM. Reason: Please don't quote unnecessarily!

  13. #13
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Re: Extract Date from Text

    @jindon,

    Sorry, I have noticed that you code displays wrong year. All the dates related to 2019 is extracted as 2020.
    Last edited by AliGW; 03-29-2020 at 06:35 AM. Reason: Please don't quote unnecessarily!

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,037

    Re: Extract Date from Text

    Quote Originally Posted by Barieq View Post
    @AliGW your formula result is #value
    No, they work fine - see the attachment.
    Attached Files Attached Files

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,536

    Re: Extract Date from Text

    Quote Originally Posted by Barieq View Post
    @jindon,

    Sorry, I have noticed that you code displays wrong year. All the dates related to 2019 is extracted as 2020.
    Ahhh,

    Try this then
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Re: Extract Date from Text

    Quote Originally Posted by AliGW View Post
    No, they work fine - see the attachment.
    @AliGW,

    When I drag the formula from E6 some cells result is #VALUE!. Even the file attached by you showing wrong result. All the dates in the test is dd/mm/yyyy format. Check below the result.

    Some Text | 01/04/2019 To 31/03/2020 {01-Apr-2019 To 31-Mar-2020} 01-Apr-19 31-Mar-20
    Some Text | 25/09/1440 To 24/09/1441 {30-May-2019 To 17-May-2020} #VALUE! #VALUE!
    Some Text | 10/06/2019 To 09/06/2020 {10-Jun-2019 To 09-Jun-2020} 06-Oct-19 06-Sep-20
    Some Text | 10/06/2019 To 09/06/2020 {10-Jun-2019 To 09-Jun-2020} 06-Oct-19 06-Sep-20
    Some Text | 17/10/1440 To 16/04/1441 {20-Jun-2019 To 13-Dec-2019} #VALUE! #VALUE!
    Some Text | 17/10/1440 To 16/04/1441 {20-Jun-2019 To 13-Dec-2019} #VALUE! #VALUE!
    Some Text | 01/11/1440 To 29/10/1441 {04-Jul-2019 To 21-Jun-2020} 11-Jan-19 #VALUE!
    Some Text | 01/11/1440 To 29/10/1441 {04-Jul-2019 To 21-Jun-2020} 11-Jan-19 #VALUE!
    Some Text | 20/12/1440 To 19/12/1441 {21-Aug-2019 To 09-Aug-2020} #VALUE! #VALUE!
    Some Text | 20/08/2019 To 19/02/2020 {20-Aug-2019 To 19-Feb-2020} #VALUE! #VALUE!
    Some Text | 17/04/1441 To 16/10/1441 {14-Dec-2019 To 08-Jun-2020} #VALUE! #VALUE!
    Some Text | 17/04/1441 To 16/10/1441 {14-Dec-2019 To 08-Jun-2020} #VALUE! #VALUE!
    Some Text | 01/01/2020 To 30/06/2020 {01-Jan-2020 To 30-Jun-2020} 01-Jan-20 #VALUE!
    Some Text | 01/01/2020 To 30/06/2020 {01-Jan-2020 To 30-Jun-2020} 01-Jan-20 #VALUE!
    Some Text | 24/07/1440 To 23/01/1441 {31-Mar-2019 To 22-Sep-2019} #VALUE! #VALUE!
    Some Text | 24/01/1441 To 23/07/1441 {23-Sep-2019 To 18-Mar-2020} #VALUE! #VALUE!
    Some Text | 09/07/1440 To 08/07/1441 {16-Mar-2019 To 03-Mar-2020} 07-Sep-19 07-Aug-20

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,536

    Re: Extract Date from Text


  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,037

    Re: Extract Date from Text

    I am sorry, but my formulae work:

    Excel 2016 (Windows) 32 bit
    D
    E
    F
    5
    Header Date From Date To
    6
    Some Text | 01/04/2019 To 31/03/2020 {01-Apr-2019 To 31-Mar-2020}
    01-Apr-19
    31-Mar-20
    7
    Some Text | 25/09/1440 To 24/09/1441 {30-May-2019 To 17-May-2020}
    25-Sep-19
    24-Sep-20
    8
    Some Text | 10/06/2019 To 09/06/2020 {10-Jun-2019 To 09-Jun-2020}
    10-Jun-19
    09-Jun-20
    9
    Some Text | 10/06/2019 To 09/06/2020 {10-Jun-2019 To 09-Jun-2020}
    10-Jun-19
    09-Jun-20
    10
    Some Text | 17/10/1440 To 16/04/1441 {20-Jun-2019 To 13-Dec-2019}
    17-Oct-19
    16-Apr-20
    11
    Some Text | 17/10/1440 To 16/04/1441 {20-Jun-2019 To 13-Dec-2019}
    17-Oct-19
    16-Apr-20
    12
    Some Text | 01/11/1440 To 29/10/1441 {04-Jul-2019 To 21-Jun-2020}
    01-Nov-19
    29-Oct-20
    13
    Some Text | 01/11/1440 To 29/10/1441 {04-Jul-2019 To 21-Jun-2020}
    01-Nov-19
    29-Oct-20
    14
    Some Text | 20/12/1440 To 19/12/1441 {21-Aug-2019 To 09-Aug-2020}
    20-Dec-19
    19-Dec-20
    15
    Some Text | 20/08/2019 To 19/02/2020 {20-Aug-2019 To 19-Feb-2020}
    20-Aug-19
    19-Feb-20
    16
    Some Text | 17/04/1441 To 16/10/1441 {14-Dec-2019 To 08-Jun-2020}
    17-Apr-20
    16-Oct-20
    17
    Some Text | 17/04/1441 To 16/10/1441 {14-Dec-2019 To 08-Jun-2020}
    17-Apr-20
    16-Oct-20
    18
    Some Text | 01/01/2020 To 30/06/2020 {01-Jan-2020 To 30-Jun-2020}
    01-Jan-20
    30-Jun-20
    19
    Some Text | 01/01/2020 To 30/06/2020 {01-Jan-2020 To 30-Jun-2020}
    01-Jan-20
    30-Jun-20
    20
    Some Text | 24/07/1440 To 23/01/1441 {31-Mar-2019 To 22-Sep-2019}
    24-Jul-19
    23-Jan-20
    21
    Some Text | 24/01/1441 To 23/07/1441 {23-Sep-2019 To 18-Mar-2020}
    24-Jan-20
    23-Jul-20
    22
    Some Text | 09/07/1440 To 08/07/1441 {16-Mar-2019 To 03-Mar-2020}
    09-Jul-19
    08-Jul-20
    Sheet: Sheet1

    I am not in the US - dates in the UK are also dd/mm/yyyy.

    Even the file attached by you showing wrong result.
    Not here!
    Last edited by AliGW; 03-29-2020 at 07:14 AM.

  19. #19
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Re: Extract Date from Text

    Example look into row 7 Actual Date is {30-May-2019 To 17-May-2020} but your result is something else. I don't know how you say your formula works.
    Last edited by AliGW; 03-29-2020 at 07:25 AM. Reason: Please don't quote unnecessarily!

  20. #20
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,037

    Re: Extract Date from Text

    OK - I give up. You said my formulae were returning #VALUE! errors - they were not

    Use one of the other solutions, and PLEASE stop quoting posts unnecessarily - it's just clutter.

  21. #21
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Re: Extract Date from Text

    Quote Originally Posted by jindon View Post
    @Jindon,

    Perfect, You are always genius.

  22. #22
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,037

    Re: Extract Date from Text

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  23. #23
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,536

    Re: Extract Date from Text

    Glad it works.

    Dates in Excel is a nightmare...

  24. #24
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,152

    Re: Extract Date from Text

    ... especially for settings other than English-American ...

  25. #25
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Re: Extract Date from Text

    Quote Originally Posted by porucha vevrku View Post
    ... especially for settings other than English-American ...
    Yes, I agree.

  26. #26
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Re: Extract Date from Text

    Quote Originally Posted by AliGW View Post
    OK - I give up. You said my formulae were returning #VALUE! errors - they were not

    Use one of the other solutions, and PLEASE stop quoting posts unnecessarily - it's just clutter.
    Now it is Solved.

  27. #27
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,037

    Re: Extract Date from Text

    It's the US dates that bugger everything up! Why they have to do it the wrong way round, goodness only knows ...


  28. #28
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Extract Date from Text

    Here a Jindon's code remake which seems giving good result
    BTW @Jindon could you explain the purpose of
    Please Login or Register  to view this content.
    Here the full code
    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  29. #29
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,536

    Re: Extract Date from Text

    Yeah, it should be 11, not 9, so it only returns 20 for year...
    Please Login or Register  to view this content.
    Array(1, 3) is to convert string like 01-Apr-2019 to a serial date as d/m/y.

  30. #30
    Registered User
    Join Date
    02-23-2020
    Location
    France
    MS-Off Ver
    2019
    Posts
    44

    Re: Extract Date from Text

    Quote Originally Posted by Barieq View Post
    @ArdusPetus

    I like the code which check the Hijri Date, but some of the rows the date displayed is wrong. Can you please look into this.
    What is wrong with the results you quote ? What should be the results ?

  31. #31
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Extract Date from Text

    Array(1, 3) is to convert string like 01-Apr-2019 to a serial date as d/m/y.
    Thx Jindon

+ 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 date from text
    By Prashanth.Akula in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-27-2019, 06:30 PM
  2. [SOLVED] Extract Date from text
    By JGREEN17 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-09-2018, 12:37 PM
  3. [SOLVED] extract date from text
    By mazan2010 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-26-2017, 03:17 PM
  4. [SOLVED] Extract Date from text
    By hkbhansali in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-18-2016, 11:58 AM
  5. extract a date from a text string
    By theobrandt in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-02-2016, 08:30 AM
  6. extract text from date
    By interested in forum Excel General
    Replies: 24
    Last Post: 02-21-2012, 09:05 AM
  7. EXTRACT TEXT FROM A DATE
    By Ronbo in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-01-2005, 04:06 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