Forum Discussion
Extract mm.yyyy from text
Hello,
I have a column with text with different length, which contains month and year in a format mm.yyyy and it could be located at a different place within the cell. How can I extract the mm.yyyy only?
Thanks a lot in advance.
8 Replies
- John GruberBrass Contributor
=REGEXEXTRACT(A1, "\d{2}\.\d{4}")
- SDj1Copper Contributor
invoice 2-10747 dated 12.2024.pdf
invoice 2-10846 dated 04.10.2024.pdf
invoice 2-11154 dated 12 December 2024.pdf
invoice 2-11196 dated 16 December 2024.pdf
invoice 2-11339 dated 29 January 2025.pdf
invoice 2-11427 dated 21 February 2025.pdf
dated 31.03.2025 invoice 2-11559.pdf
invoice 2-11567 dated 08 April 2025.pdf
dated 13 May 2025 invoice 2-11706.pdf
invoice 2-11928 dated 19 June 2025.pdf
Excel 365 for Winfows
- joshaaliOccasional Reader
You can extract **mm.yyyy** from text using a few different approaches, depending on your Excel version.
Excel (Microsoft 365 / Excel 2021+) – Best Method
Use TEXTSPLIT + FILTER with a pattern match:
=TEXTBEFORE(TEXTAFTER(A1,"."),".")❌ *This won’t reliably work when the position varies.*
Recommended (Robust) Formula
This works no matter where mm.yyyy appears in the text:
=TEXTJOIN("",,MID(A1,SEQUENCE(LEN(A1)),1))❌ *Still not precise for pattern matching.*
Correct & Reliable Solution (All Excel Versions)
Using MID + SEARCH
=MID(A1,SEARCH(".",A1)-2,7)
If you want, tell me your Excel version and I’ll tailor the best formula for you. - Harun24HRBronze Contributor
REGEXEXTRACT() or FILTERXML() may help. Post few of a sample data.
- LorenzoSilver Contributor
Hi
For this kind of things you should share - say 10 to 20 representative & different - of your actual text values + the version of Excel you run & on which platform (Windows, Mac, Web...)- SDj1Copper Contributor
Hi
This is the sample of the text in the various cells from which I would like to extract the date in MM.YYYY format:
invoice 2-10747 dated 12.2024.pdf
invoice 2-10846 dated 04.10.2024.pdf
invoice 2-11154 dated 12 December 2024.pdf
invoice 2-11196 dated 16 December 2024.pdf
invoice 2-11339 dated 29 January 2025.pdf
invoice 2-11427 dated 21 February 2025.pdf
dated 31.03.2025 invoice 2-11559.pdf
invoice 2-11567 dated 08 April 2025.pdf
dated 13 May 2025 invoice 2-11706.pdf
invoice 2-11928 dated 19 June 2025.pdf
Excel 365 for Windows
- LorenzoSilver Contributor
Hi SDj1
Your examples were definitively required as your pseudo-dates are not always in mm.yyyy format as you initially said. Anyway, with your example in B2:B21 below (pic. cropped)
in D2:
=LET( afterDated, TEXTAFTER( B2:B21, "dated " ), beforePdf, TEXTBEFORE( afterDated, ".pdf" ), TRIM( TEXTBEFORE( beforePdf, " invoice ",,,, beforePdf ) ) )Attaching a sample file & crossing figures it won't be dropped by this site...
EDIT A variant that replaces months in MMMM format with their corresponding number:
With a LAMBDA named EXTRACT_DATE stored in the Name Manager, in F2:
=EXTRACT_DATE( B2:B21 )where LAMBDA is:
// EXTRACT_DATE =LAMBDA( reference, LET( seq, SEQUENCE( 12 ), months, TEXT( DATE( 2000, seq, 1 ), " MMMM " ), replacer, IF( seq < 10, ".0" & seq, "." & seq ) & ".", EXTRACT, LAMBDA( rw, LET( searchMonths, IFERROR( SIGN( SEARCH( months, rw ) ), 0 ), monthsAsMM, IF( SUM( searchMonths ) = 0, rw, SUBSTITUTE( rw, XLOOKUP( 1, searchMonths, months ), XLOOKUP( 1, searchMonths, replacer ) ) ), TEXTBEFORE( TEXTAFTER( monthsAsMM, "dated " ), {".pdf"," invoice "} ) ) ), BYROW( reference, EXTRACT ) ) )
- SDj1Copper Contributor
Thank you and sorry.
These are some of the texts in the column:
invoice 2-10747 dated 12.2024.pdf invoice 2-10846 dated 04.10.2024.pdf invoice 2-11154 dated 12 December 2024.pdf invoice 2-11196 dated 16 December 2024.pdf invoice 2-11339 dated 29 January 2025.pdf invoice 2-11427 dated 21 February 2025.pdf invoice 2-11559 dated 31.03.2025.pdf invoice 2-11567 dated 08 April 2025.pdf invoice 2-11706 dated 13 May 2025.pdf invoice 2-11928 dated 19 June 2025.pdf The problem is with the cells where the Month is shown as a name of the month instead as 03.2024, for example. This is Excel 365 for Windows. And in some cells the date is in the middle of the cell and not in the end.