Extracting 2 text dates from a cell into 2 new cells

taleye

Active Member
Joined
Oct 22, 2008
Messages
299
Hi

I've been away from Excel for a very long time and my attempts at mid right len formulas are getting me nowhere :(

I have a single cell that contains a string of text "# Date: Oct 1 2017 - Oct 31 2017"

When someone uses the spreadsheet data is dumped into the file and the cell is populated with whatever daterange they may be looking at, I have to create 2 formulas that will take those 2 written dates and have them converted into actual dates so that calculations can be made on the date range itself such as annualising benefit etc.

The issue is getting the two dates noting that the day could be single or double digit and then converting the two text strings into date format!

Can anybody get me started or help me out here please :eek:

Thanks!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,

Let's say A1 is the cell that contains a string of text "# Date: Oct 1 2017 - Oct 31 2017"

B1 first date =TRIM(MID(TRIM(MID(A1,8,12)),FIND(" ",TRIM(MID(A1,8,12))),3))&"/"&MONTH((LEFT(TRIM(MID(A1,8,12)),FIND(" ",TRIM(MID(A1,8,12)))-1)&" 0"))&"/"&RIGHT(TRIM(MID(A1,8,12)),4)

C1 second date =TRIM(MID(TRIM(RIGHT(A1,11)),FIND(" ",TRIM(RIGHT(A1,11))),3))&"/"&MONTH((LEFT(TRIM(RIGHT(A1,11)),FIND(" ",TRIM(RIGHT(A1,11)))-1)&" 0"))&"/"&RIGHT(TRIM(RIGHT(A1,11)),4)
 
Upvote 0
Ok,

a work in progress.

Let's say the text is found in G6, then ...

To extract the first date, use ... =MID(G6,FIND(CHAR(1),SUBSTITUTE(G6," ",CHAR(1),2))+1,(FIND(CHAR(1),SUBSTITUTE(G6," ",CHAR(1),5))-FIND(CHAR(1),SUBSTITUTE(G6," ",CHAR(1),2)))-1)

To extract the second date, use ... =MID(G6,FIND(CHAR(1),SUBSTITUTE(G6," ",CHAR(1),6))+1,LEN(G6)-FIND(CHAR(1),SUBSTITUTE(G6," ",CHAR(1),6)))

Am currently playing with ideas to allow excel to recognise these as dates but haven't solved that yet.

Kind regards,

Chris
 
Upvote 0
Assuming the string is in cell A1

First date :

Code:
=DATEVALUE(TRIM(MID($A1,FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),3))+1,FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),4))-FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),3))))&"-"&TRIM(MID($A1,FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),2))+1,FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),3))-FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),2))))&"-"&TRIM(MID($A1,FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),4))+1,FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),5))-FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),4)))))

Second Date :

Code:
=DATEVALUE(TRIM(MID($A1,FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),7))+1,FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),8))-FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),7))))&"-"&TRIM(MID($A1,FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),6))+1,FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),7))-FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),6))))&"-"&TRIM(MID($A1,FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),8))+1,LEN($A1)-FIND(CHAR(1),SUBSTITUTE($A1," ",CHAR(1),8)))))
 
Upvote 0
And yet another option for you to try which returns real Excel date serial numbers.

This assumes you are using a UK system that expects dates in DD/MM/YYYY format.


Excel 2013/2016
ABC
1# Date: Oct 1 2017 - Oct 31 201701/10/201731/10/2017
2# Date: Oct 10 2017 - Oct 31 201710/10/201731/10/2017
3# Date: Oct 1 2017 - Oct 2 201701/10/201702/10/2017
4# Date: Oct 10 2017 - Dec 2 201710/10/201702/12/2017
Sheet1
Cell Formulas
RangeFormula
B1=0+(MID(A1,13,2)&MID(A1,9,3)&MID(A1,15,5))
C1=0+(MID(MID(A1,FIND("-",A1)+2,11),5,2)&LEFT(MID(A1,FIND("-",A1)+2,11),3)&RIGHT(MID(A1,FIND("-",A1)+2,11),4))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,767
Messages
6,126,773
Members
449,336
Latest member
p17tootie

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