Extract dates from text string

Tvynn

New Member
Joined
Oct 18, 2018
Messages
10
Hi, I'd like to extract out the dates from text string by using formula instead of text to column, is it possible? After that, i'd like to calculate the Number of Days Between Two Dates, and shows it blank if nothing to deduct instead of showing date. Appreciate your kind help, thanks!

<style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>
Original textdate 1date 2date 3date 4Number of Days Between Two DatesNumber of Days Between First & Last Date

1a@mail.com/hard(amy/2jan19);b@mail.com/hard(ken/20dec18);c@mail.com/hard(jane/01nov18);d@mail.com/hard(bill/15oct18);2Jan1920Dec1801Nov1815Oct1813491779
2a@mail.com/hard(amy/3jan19);b@mail.com/hard(jane/5dec18);c@mail.com/hard(kate/15oct18);3Jan1905Dec1815Oct18295180
3a@mail.com/hard(amy/9jan19);b@mail.com/hard(jane/8dec18);9Jan198Dec183232

<colgroup><col style="width: 20px"><col width="628"><col width="58"><col width="58"><col width="58"><col width="58"><col width="63"><col width="63"><col width="63"><col width="74"></colgroup><tbody>
</tbody>
<style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style><style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
you have jane and ken at the same location, will that not create an issue in data quality ?
 
Upvote 0
Hi Mole,

Nope those names will not create any issue, what i want is to extract out those dates only

Thanks


Hi, I'd like to extract out the dates from text string by using formula instead of text to column, is it possible? After that, i'd like to calculate the Number of Days Between Two Dates, and shows it blank if nothing to deduct instead of showing date. Appreciate your kind help, thanks!

<style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>
Original textdate 1date 2date 3date 4Number of Days Between Two DatesNumber of Days Between First & Last Date
1a@mail.com/hard(amy/2jan19);b@mail.com/hard(ken/20dec18);c@mail.com/hard(jane/01nov18);d@mail.com/hard(bill/15oct18);2Jan1920Dec1801Nov1815Oct1813491779
2a@mail.com/hard(amy/3jan19);b@mail.com/hard(jane/5dec18);c@mail.com/hard(kate/15oct18);3Jan1905Dec1815Oct18295180
3a@mail.com/hard(amy/9jan19);b@mail.com/hard(jane/8dec18);9Jan198Dec183232

<tbody>
</tbody>
<style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style><style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>
 
Upvote 0
you can try to play with PowerQuery:

Text Between DelimitersText Between Delimiters.1Text Between Delimiters.2Text Between Delimiters.3SubtractionSubtraction.1Subtraction.2Addition
02/01/2019​
20/12/2018​
01/11/2018​
15/10/2018​
13​
49​
17​
79​
03/01/2019​
05/12/2018​
15/10/2018​
29​
51​
80​
09/01/2019​
08/12/2018​
32​
32​

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Original text", type text}}),
    #"Inserted Text Between Delimiters" = Table.AddColumn(#"Changed Type", "Text Between Delimiters", each Text.BetweenDelimiters([Original text], "/", ")", 1, 0), type text),
    #"Inserted Text Between Delimiters1" = Table.AddColumn(#"Inserted Text Between Delimiters", "Text Between Delimiters.1", each Text.BetweenDelimiters([Original text], "/", ")", 3, 0), type text),
    #"Inserted Text Between Delimiters2" = Table.AddColumn(#"Inserted Text Between Delimiters1", "Text Between Delimiters.2", each Text.BetweenDelimiters([Original text], "/", ")", 5, 0), type text),
    #"Inserted Text Between Delimiters3" = Table.AddColumn(#"Inserted Text Between Delimiters2", "Text Between Delimiters.3", each Text.BetweenDelimiters([Original text], "/", ")", 7, 0), type text),
    #"Parsed Date" = Table.TransformColumns(#"Inserted Text Between Delimiters3",{{"Text Between Delimiters", each Date.From(DateTimeZone.From(_)), type date}, {"Text Between Delimiters.1", each Date.From(DateTimeZone.From(_)), type date}, {"Text Between Delimiters.2", each Date.From(DateTimeZone.From(_)), type date}, {"Text Between Delimiters.3", each Date.From(DateTimeZone.From(_)), type date}}),
    #"Inserted Date Subtraction" = Table.AddColumn(#"Parsed Date", "Subtraction", each Duration.Days([Text Between Delimiters] - [Text Between Delimiters.1]), Int64.Type),
    #"Inserted Date Subtraction1" = Table.AddColumn(#"Inserted Date Subtraction", "Subtraction.1", each Duration.Days([Text Between Delimiters.1] - [Text Between Delimiters.2]), Int64.Type),
    #"Inserted Date Subtraction2" = Table.AddColumn(#"Inserted Date Subtraction1", "Subtraction.2", each Duration.Days([Text Between Delimiters.2] - [Text Between Delimiters.3]), Int64.Type),
    #"Inserted Date Subtraction3" = Table.AddColumn(#"Inserted Date Subtraction2", "Subtraction.3", each Duration.Days([Text Between Delimiters] - [Text Between Delimiters.3]), Int64.Type),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Date Subtraction3",{"Subtraction.3"}),
    #"Inserted Sum" = Table.AddColumn(#"Removed Columns", "Addition", each List.Sum({[Subtraction], [Subtraction.1], [Subtraction.2]}), Int64.Type),
    #"Removed Columns1" = Table.RemoveColumns(#"Inserted Sum",{"Original text"})
in
    #"Removed Columns1"[/SIZE]

M-code can be optimized but I'm too lazy ;)
 
Upvote 0
Hi Sandy,

Thanks for your kind help, but i never use this method before, seems like writing a macro code, guess need to insert file for it to work? Think i need to try up first

Thanks ya


you have jane and ken at the same location, will that not create an issue in data quality ?
 
Upvote 0
Assuming your data starts in cell A1, put this formula in cell B1 and copy it across for as many columns as you think you will ever have dates to fill, then copy all of those cells down to the bottom of your data...

=TRIM(RIGHT(SUBSTITUTE(TRIM(MID(SUBSTITUTE(")"&$A1,")",REPT(" ",500)),COLUMNS($B:B)*500,500)),"/",REPT(" ",500)),500))

Note: I am assuming none of your cells in Column A will ever contain more than 500 characters total.
 
Last edited:
Upvote 0
Thanks so much for your help Rick! it's easy and worked perfectly! And thanks also Sandy eventhough im not able to try up at the moment.

By the way, i have further step to do, that is after getting the number of days between 2 dates, if it's more than 30 days, then i would like to remove the statement between two ";" from the text string as red font below, wonder if it's possible? Else i may use another method as well, thanks again and god bless!
[FONT=&quot]1[/FONT][FONT=&quot]a@mail.com/hard(amy/2jan19);b@mail.com/hard(ken/20dec18);c@mail.com/hard(jane/01nov18);d@mail.com/hard(bill/15oct18);[/FONT][FONT=&quot]2jan19[/FONT][FONT=&quot]20dec18[/FONT][FONT=&quot]01nov18[/FONT][FONT=&quot]15oct18[/FONT][FONT=&quot];[/FONT][FONT=&quot]13[/FONT][FONT=&quot]49[/FONT][FONT=&quot]17[/FONT]
[FONT=&quot]2[/FONT][FONT=&quot]a@mail.com/hard(amy/3jan19);b@mail.com/hard(jane/5dec18);c@mail.com/hard(kate/15oct18);[/FONT][FONT=&quot]3jan19[/FONT][FONT=&quot]5dec18[/FONT][FONT=&quot]15oct18[/FONT][FONT=&quot];[/FONT][FONT=&quot]29[/FONT][FONT=&quot]51[/FONT][FONT=&quot]#VALUE![/FONT]
[FONT=&quot]3[/FONT][FONT=&quot]a@mail.com/hard(amy/9jan19);b@mail.com/hard(jane/8dec18);[/FONT][FONT=&quot]9jan19[/FONT][FONT=&quot]8dec18[/FONT][FONT=&quot]32[/FONT][FONT=&quot]FALSE[/FONT][FONT=&quot]FALSE[/FONT]
[FONT=&quot]4[/FONT][FONT=&quot]a@mail.com/hard(amy/9jan19)[/FONT][FONT=&quot]9jan19[/FONT][FONT=&quot];[/FONT][FONT=&quot]#VALUE![/FONT][FONT=&quot]FALSE[/FONT][FONT=&quot]FALSE[/FONT]

<colgroup><col style="width: 27px;"><col width="611"><col width="61"><col width="61"><col width="61"><col width="61"><col width="61"><col width="44"><col width="44"><col width="44"></colgroup><tbody>
</tbody>
 
Upvote 0
@Rick, this is very useful, im looking for this same solution but my source is different, how should be modified if i need to extract dates from a text cell like this:
_________________________________________
Pardot - Database - Automation Rules (unlimited)
1 license x $0.00/mo x 8 months

Term: 5/31/2019 - 1/30/2020

<tbody>
</tbody>
__________________________________

The word "term", will not always be there, thats why Im looking for a way to recognize the date format and extract 1 by 1 into separate columns.

Any help will be highly appreciated.
 
Last edited:
Upvote 0
Assuming your data starts in cell A1, put this formula in cell B1 and copy it across for as many columns as you think you will ever have dates to fill, then copy all of those cells down to the bottom of your data...

=TRIM(RIGHT(SUBSTITUTE(TRIM(MID(SUBSTITUTE(")"&$A1,")",REPT(" ",500)),COLUMNS($B:B)*500,500)),"/",REPT(" ",500)),500))

Note: I am assuming none of your cells in Column A will ever contain more than 500 characters total.


@Rick, this is very useful, im looking for this same solution but my source is different, how should be modified if i need to extract dates from a text cell like this:

Pardot - Database - Automation Rules (unlimited)
1 license x $0.00/mo x 8 months

Term: 5/31/2019 - 1/30/2020

<tbody>
</tbody>


The word "term", will not always be there, thats why Im looking for a way to recognize the date format and extract 1 by 1 into separate columns.

Any help will be highly appreciated.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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