Text and Date Functions
Clean and reshape text with TRIM, LEFT, MID and TEXTJOIN, combine values into labels, and calculate with dates using TODAY, EOMONTH and NETWORKDAYS.
Welcome back!
Step 1 of 13Learn
Fixing messy text
A list exported from an old system arrives looking like this: " smith, JOHN ", "LEE, anna", "o'brien, PAT ". Before you can match, count or mail-merge these names, they need cleaning. Text functions do it with formulas you write once and copy down.
- TRIM(text) removes spaces at the start and end and reduces runs of spaces inside to single spaces.
=TRIM(" smith, JOHN ")returns "smith, JOHN". It's the single most useful cleaning function, because invisible spaces break lookups and COUNTIF criteria. - UPPER, LOWER, PROPER change case:
=PROPER("smith, JOHN")returns "Smith, John". - LEN(text) counts characters, including spaces. If LEN of "West" returns 5, there's a hidden space.
- CLEAN(text) removes non-printing characters that sometimes sneak in from web pages or other systems.
Functions can be nested, so one formula can do several jobs: =PROPER(TRIM(A2)).
A typical workflow: put the cleaning formula in a helper column next to the messy one, copy it down, then convert the results to fixed values with Copy, Paste Special > Values so you can delete the original column. If you delete the original while the formulas still depend on it, they turn into #REF! errors.
Remember that text functions return text. If you extract "2026" from a code, it's the text "2026", not the number; wrap it in VALUE() if you need to calculate with it.
Step 2 of 13Practice · Diagram
Cleaning one messy name
Which step stops the hidden spaces from breaking lookups?
Tap the shape that answers the question, then press Check.
- " smith, JOHN "
Exported from an old system.
- TRIM
"smith, JOHN": outer spaces gone, inner runs reduced to one.
- PROPER
"Smith, John".
- Paste Special > Values
Freeze the result before deleting the original column.
Step 3 of 13Learn
Taking text apart: LEFT, RIGHT, MID and FIND
Codes often pack several facts into one string. An invoice number like INV-2026-0417 holds a prefix, a year and a sequence number. Three functions extract pieces by position:
- LEFT(text, n): the first n characters.
=LEFT(A2, 3)returns "INV". - RIGHT(text, n): the last n characters.
=RIGHT(A2, 4)returns "0417". - MID(text, start, n): n characters starting at position start.
=MID(A2, 5, 4)returns "2026". Position counting starts at 1, and the dash at position 4 is counted too.
When the pieces don't have fixed lengths, find the position of a separator first. FIND(find_text, within_text) returns where something appears: =FIND(",", "Smith, John") returns 6. So the last name is =LEFT(A2, FIND(",", A2) - 1), everything before the comma. (SEARCH works like FIND but ignores case and allows wildcards.)
Microsoft 365 adds simpler tools: TEXTBEFORE(A2, ",")** and **TEXTAFTER(A2, ", ") return the parts around a separator, and TEXTSPLIT splits text into several cells at once.
For one-off jobs, Flash Fill is often fastest: type the result you want for the first row or two, press Ctrl+E, and Excel copies the pattern. Check the results carefully; Flash Fill guesses, and unusual rows can trip it up. Unlike formulas, it does not update if the source changes.
Step 4 of 13Practice · Fill in the blanks
Fill in the blanks
For the text "INV-2026-0417": =MID(A2, 5, 4) returns , and =LEN(A2) returns .
Step 5 of 13Diagram
Taking apart INV-2026-0417
Tap a shape with to see more.
- INV-2026-0417
- =LEFT(A2, 3)
"INV"
- =MID(A2, 5, 4)
"2026": 4 characters starting at position 5. Still text until wrapped in VALUE.
- =RIGHT(A2, 4)
"0417"
- =LEN(A2)
13 characters, dashes included.
Step 6 of 13Learn
Putting text together
Joining text is called concatenation. The ampersand (&) is the simplest tool:
=A2&" "&B2joins a first name and a last name with a space: "Lee" and "Kim" become "Lee Kim". Forgetting the " " in the middle gives "LeeKim".="Order "&C2&" ships on "&D2builds a sentence from several cells.
CONCAT does the same as a function, and TEXTJOIN adds a delimiter between items and can skip blanks: =TEXTJOIN(", ", TRUE, A2:E2) turns five cells into "red, green, blue" even if two are empty.
When numbers or dates are joined into text, they lose their formatting: ="Total: "&B2 might show "Total: 1234.5" and a date might appear as 46096. Use TEXT(value, format) to control the display:
="Total: "&TEXT(B2, "$#,##0.00")gives "Total: $1,234.50".="Due "&TEXT(D2, "mmm d, yyyy")gives "Due Mar 15, 2026".
In the format codes, 0 forces a digit, # shows a digit only if needed, and the comma adds thousands separators. TEXT returns text, so use it only for labels and messages, never for numbers you still need to add up.
Step 7 of 13Practice · Choose one
A2 holds "Ana", B2 holds "Ruiz" and C2 holds the number 0.25 formatted as 25%. What does =A2&" "&B2&": "&C2 display?
Step 8 of 13Learn
Working with dates
Because dates are numbers (day counts), date math is mostly subtraction and addition. A set of functions handles the rest:
| Function | Example | Returns |
|---|---|---|
| TODAY() | =TODAY() | the current date, updated each time the sheet recalculates |
| DATE(y, m, d) | =DATE(2026, 7, 4) | the date July 4, 2026 |
| YEAR, MONTH, DAY | =MONTH(A2) | the month number, 1 to 12 |
| EDATE(start, months) | =EDATE(A2, 3) | the same day 3 months later |
| EOMONTH(start, months) | =EOMONTH(A2, 0) | the last day of A2's month |
| WEEKDAY(date) | =WEEKDAY(A2) | 1 (Sunday) to 7 (Saturday) by default |
| NETWORKDAYS(start, end) | =NETWORKDAYS(A2, B2) | working days between two dates, Monday to Friday, both ends included |
| DATEDIF(start, end, "y") | =DATEDIF(B2, TODAY(), "y") | complete years, such as age or tenure |
Practical patterns: an invoice dated in A2 with 30-day terms is due on =A2+30, and days overdue is =TODAY()-(A2+30). A subscription that renews monthly renews on =EDATE(A2, 1). A "month" column for grouping is =EOMONTH(A2, -1)+1, the first day of the month.
Because TODAY() recalculates, a sheet showing "days overdue" is correct every morning without edits. The flip side: if you need to record when something happened, type the date (or press Ctrl+;), since a TODAY() formula will change tomorrow.
Step 9 of 13Practice · Choose one
An invoice dated March 10, 2026 is due 45 days later. What does =A2+45 return, with A2 holding the invoice date?
Step 10 of 13Learn
Common date problems and fixes
Most date trouble falls into a few patterns:
- Dates stored as text. Imported dates that sit on the left of the cell will not sort, filter or subtract properly. Fix them with Data > Text to Columns (choose the date order, such as MDY), with DATEVALUE, or with DATE built from LEFT, MID and RIGHT pieces.
- Day and month swapped. A file created with day-month order and opened with month-day settings turns 03/04/2026 into March 4 instead of April 3, while 25/04/2026 stays as text because there is no month 25. A column where some dates are right-aligned and others left-aligned is the telltale sign.
- A result that looks like a date. Subtracting two dates sometimes displays as "1/30/1900". The answer, 30 days, is correct; change the format to General or Number.
- Times past midnight. A shift from 10 PM to 6 AM gives a negative result. Use
=MOD(end-start, 1)to wrap around midnight, then multiply by 24 for hours. - Two-digit years. Typing 1/5/30 may be read as 1930 or 2030 depending on settings. Type four-digit years.
When a report must be read worldwide, display dates in an unambiguous format like 2026-04-03 or 3 Apr 2026, even if your own settings show month first.
Step 11 of 13Compare
Date symptoms and their fixes
| Aspect | Symptom | Fix |
|---|---|---|
| Dates stored as text | Left-aligned, won't sort or subtract | Text to Columns (MDY), DATEVALUE or DATE |
| Day and month swapped | Mix of right- and left-aligned dates | Re-import with the right date order |
| Result shows 1/30/1900 | A day count formatted as a date | Format as General or Number |
| Shift past midnight | Negative hours | =MOD(end-start, 1)*24 |
| Two-digit years | 1930 or 2030? | Type four-digit years |
Step 12 of 13Practice · True or false
A cell containing =TODAY() keeps showing the date on which the formula was first typed.
Step 13 of 13Practice · Match the pairs
Match each task to the function that handles it best.
Tap an answer, then tap the place where it belongs (or drag it there).
- Find the last day of the month for a date
- Count working days between a start and end date
- Remove extra spaces from imported names
- Join a list of cells with commas, skipping blanks
- Get everything before the first comma by position
Lesson complete!