extract date from string

doriannjeshi

Active Member
Joined
Apr 5, 2015
Messages
338
Office Version
  1. 365
Platform
  1. Windows
Hello,

I need to extract the dates from a string but I am having mixed results

the date format I need is dd/mm/yyyy and possibly the hours in another column

Feb 6, 1930 1:21 PM Mars enters Aquarius
Mar 17, 1930 12:55 AM Mars enters Pisces
Apr 24, 1930 12:27 PM Mars enters Aries
June 2, 1930 10:15 PM Mars enters Taurus
July 14, 1930 7:54 AM Mars enters Gemini
Aug 28, 1930 6:27 AM Mars enters Cancer
 
Yes this it, thank you !
Thanks to all for coming up with solutions!
Peter_SSs, rlv01, shinigamilight !
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
The formula you show there is nothing like the one you posted & said you had tested with 100% success.
More than that, the new formula still has not been tested on the actual sample data provided in posts 1, 3 & 6. Here is a section that I have tested.

doriannjeshi.xlsm
FH
1Feb 6, 1930 1:21 PM Mars enters Aquarius1:21 PM
2Mar 17, 1930 12:55 AM Mars enters Pisces12:55 AM
3Apr 24, 1930 12:27 PM Mars enters Aries12:27 PM
4June 2, 1930 10:15 PM Mars enters Taurus10:15 PM
5July 14, 1930 7:54 AM Mars enters Gemini7:54 AM
6Aug 28, 1930 6:27 AM Mars enters Cancer6:27 AM
7Apr 2, 2011 12:51 AM Mars enters Aries#VALUE!
8Aug 3, 2011 5:22 AM Mars enters Cancer#VALUE!
9July 3, 2012 8:32 AM Mars enters Libra#VALUE!
10Oct 6, 2012 11:21 PM Mars enters Sagittarius#VALUE!
11Feb 1, 2013 8:54 PM Mars enters Pisces#VALUE!
12Dec 7, 2013 3:41 PM Mars enters Libra#VALUE!
13Dec 4, 2014 6:57 PM Mars enters Aquarius#VALUE!
14Jan 12, 2015 5:20 AM Mars enters Pisces5:20 AM
15Feb 19, 2015 7:11 PM Mars enters Aries7:11 PM
16Mar 31, 2015 12:26 PM Mars enters Taurus12:26 PM
17May 11, 2015 10:40 PM Mars enters Gemini10:40 PM
18Jun 24, 2015 9:33 AM Mars enters Cancer9:33 AM
19Aug 8, 2015 7:32 PM Mars enters Leo#VALUE!
20Sep 24, 2015 10:18 PM Mars enters Virgo10:18 PM
21Nov 12, 2015 4:41 PM Mars enters Libra4:41 PM
22Jan 3, 2016 9:32 AM Mars enters Scorpio#VALUE!
23Mar 5, 2016 9:29 PM Mars enters Sagittarius#VALUE!
24Aug 2, 2016 1:49 PM Mars enters Sagittarius#VALUE!
Dates Times
Cell Formulas
RangeFormula
H1:H24H1=VALUE(TRIM(REPLACE(MID(F1,FIND("@",SUBSTITUTE(F1," ","@",3)),95),FIND("Mars",MID(F1,FIND("@",SUBSTITUTE(F1," ","@",3)),95)),95,"")))
 
Upvote 0
Please see

doriannjeshi's original post on this challenge​


Information on the source information, system setup, etc. is not clear.
The Regional Settings may or may not be USA.

I used Search and Replace to remove excess spaces and then used a UDF.
Could the UDF be enhanced to eliminate
the TEXTBEFORE(A2," ",5)
or the
LEFT(A2,FIND("~",SUBSTITUTE(A2," ","~",5)))

VBA Code:
Function ConvertToDate(S As String)
If Not IsDate(S) Then
    ConvertToDate = CVErr(xlErrNA)
    Exit Function
End If
ConvertToDate = DateValue(S) + TimeValue(S)
End Function



T202211x.xlsm
ABC
1With 365
2Apr 2, 2011 12:51 AM Mars enters Aries2011-Apr-02 00:512011-Apr-02 00:51
3Aug 3, 2011 5:22 AM Mars enters Cancer2011-Aug-03 05:222011-Aug-03 05:22
4July 3, 2012 8:32 AM Mars enters Libra2012-Jul-03 08:322012-Jul-03 08:32
5Oct 6, 2012 11:21 PM Mars enters Sagittarius2012-Oct-06 23:212012-Oct-06 23:21
6Feb 1, 2013 8:54 PM Mars enters Pisces2013-Feb-01 20:542013-Feb-01 20:54
7Dec 7, 2013 3:41 PM Mars enters Libra2013-Dec-07 03:412013-Dec-07 03:41
8Dec 4, 2014 6:57 PM Mars enters Aquarius2014-Dec-04 06:572014-Dec-04 06:57
9Jan 12, 2015 5:20 AM Mars enters Pisces2015-Jan-12 05:202015-Jan-12 05:20
10Feb 19, 2015 7:11 PM Mars enters Aries2015-Feb-19 07:112015-Feb-19 07:11
11Mar 31, 2015 12:26 PM Mars enters Taurus2015-Mar-31 12:262015-Mar-31 12:26
12May 11, 2015 10:40 PM Mars enters Gemini2015-May-11 22:402015-May-11 22:40
13Jun 24, 2015 9:33 AM Mars enters Cancer2015-Jun-24 09:332015-Jun-24 09:33
14Aug 8, 2015 7:32 PM Mars enters Leo2015-Aug-08 07:322015-Aug-08 07:32
15Sep 24, 2015 10:18 PM Mars enters Virgo2015-Sep-24 22:182015-Sep-24 22:18
16Nov 12, 2015 4:41 PM Mars enters Libra2015-Nov-12 16:412015-Nov-12 16:41
17Jan 3, 2016 9:32 AM Mars enters Scorpio2016-Jan-03 09:322016-Jan-03 09:32
18Mar 5, 2016 9:29 PM Mars enters Sagittarius2016-Mar-05 09:292016-Mar-05 09:29
19Aug 2, 2016 1:49 PM Mars enters Sagittarius2016-Aug-02 01:492016-Aug-02 01:49
20Nov 9, 2016 12:51 AM Mars enters Aquarius2016-Nov-09 00:512016-Nov-09 00:51
21Mar 9, 2017 7:34 PM Mars enters Taurus2017-Mar-09 07:342017-Mar-09 07:34
22Jun 4, 2017 12:16 PM Mars enters Cancer2017-Jun-04 12:162017-Jun-04 12:16
23Sep 5, 2017 5:35 AM Mars enters Virgo2017-Sep-05 05:352017-Sep-05 05:35
24Dec 9, 2017 3:59 AM Mars enters Scorpio2017-Dec-09 03:592017-Dec-09 03:59
25Jul 1, 2019 7:19 PM Mars enters Leo2019-Jul-01 07:192019-Jul-01 07:19
26Oct 4, 2019 12:22 AM Mars enters Libra2019-Oct-04 00:222019-Oct-04 00:22
27Jan 3, 2020 4:37 AM Mars enters Sagittarius2020-Jan-03 04:372020-Jan-03 04:37
28Jan 6, 2021 5:27 PM Mars enters Taurus2021-Jan-06 05:272021-Jan-06 05:27
29Mar 3, 2021 10:29 PM Mars enters Gemini2021-Mar-03 22:292021-Mar-03 22:29
30Mar 6, 2022 1:23 AM Mars enters Aquarius2022-Mar-06 01:232022-Mar-06 01:23
31Jul 5, 2022 2:04 AM Mars enters Taurus2022-Jul-05 02:042022-Jul-05 02:04
32Jan 4, 2024 9:58 AM Mars enters Capricorn2024-Jan-04 09:582024-Jan-04 09:58
33Jun 9, 2024 12:35 AM Mars enters Taurus2024-Jun-09 00:352024-Jun-09 00:35
34Sep 4, 2024 3:46 PM Mars enters Cancer2024-Sep-04 03:462024-Sep-04 03:46
35Nov 3, 2024 11:09 PM Mars enters Leo2024-Nov-03 23:092024-Nov-03 23:09
36Jan 6, 2025 5:44 AM Mars Rx enters Cancer2025-Jan-06 05:442025-Jan-06 05:44
37Aug 6, 2025 7:23 PM Mars enters Libra2025-Aug-06 19:232025-Aug-06 19:23
38Nov 4, 2025 8:01 AM Mars enters Sagittarius2025-Nov-04 08:012025-Nov-04 08:01
39
3dd
Cell Formulas
RangeFormula
B2:B38B2=ConvertToDate(TEXTBEFORE(A2," ",5))
C2:C38C2=ConvertToDate(LEFT(A2,FIND("~",SUBSTITUTE(A2," ","~",5))))
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top