To change dates from DD/MM/YYYY to YYYY-MM-DD with regex, find \b(\d{2})/(\d{2})/(\d{4})\b and replace with $3-$2-$1. The three capture groups grab the day, month and year, and the replacement puts them back in ISO order, so 31/12/2025 becomes 2025-12-31. For US-style MM/DD/YYYY dates, use $3-$1-$2 instead. The same idea handles other separators, two-digit years and single-digit days, with a couple of extra steps covered below.
Every pattern here was tested, but dates are data: always check a sample of results before you trust a bulk change.
How the basic pattern works
\b(\d{2})/(\d{2})/(\d{4})\b
| Part | Matches | Group |
|---|---|---|
\b | A word boundary, so the date is not part of a longer number | |
(\d{2}) | Two digits: the day | $1 |
/ | A literal slash | |
(\d{2}) | Two digits: the month | $2 |
(\d{4}) | Four digits: the year | $3 |
Replace with $3-$2-$1 to output year, month, day separated by hyphens. If your tool uses \1 style references, write \3-\2-\1. In PowerShell, keep the replacement in single quotes: $t -replace '\b(\d{2})/(\d{2})/(\d{4})\b','$3-$2-$1'.
Common conversions
| From | To | Find | Replace |
|---|---|---|---|
| 31/12/2025 | 2025-12-31 | \b(\d{2})/(\d{2})/(\d{4})\b | $3-$2-$1 |
| 12/31/2025 (US) | 2025-12-31 | \b(\d{2})/(\d{2})/(\d{4})\b | $3-$1-$2 |
| 2025-12-31 | 12/31/2025 | \b(\d{4})-(\d{2})-(\d{2})\b | $2/$3/$1 |
| 2025-12-31 | 31/12/2025 | \b(\d{4})-(\d{2})-(\d{2})\b | $3/$2/$1 |
| 31/12/25 | 2025-12-31 | \b(\d{2})/(\d{2})/(\d{2})\b | 20$3-$2-$1 |
| 20251231 | 2025-12-31 | \b(\d{4})(\d{2})(\d{2})\b | $1-$2-$3 |
Two of these need care. The two-digit year rule assumes every date is in the 2000s; check for older dates first. The 20251231 rule matches any eight-digit number, so only use it in files where such numbers are always dates, or anchor it to the surrounding text such as date="(\d{4})(\d{2})(\d{2})".
Dots, hyphens or slashes: any separator
European data often uses dots (31.12.2025) or hyphens. To accept any of the three, but only when both separators match:
- Find:
\b(\d{2})([/.-])(\d{2})\2(\d{4})\b - Replace:
$4-$3-$1
The \2 inside the pattern is a back-reference: it requires the second separator to be the same character as the first. 31.12.2025 and 07-08-2025 match, but a mixed string like 01/02-2025 does not. Because the separator is now group 2, the year is group 4.
Single-digit days and months
Dates like 1/5/2025 need zero padding to become 2025-05-01. Regex cannot pad conditionally in one step, so run three rules in order:
- Pad a single-digit day: find
\b(\d)(?=/\d{1,2}/\d{4}\b), replace with0$1. - Pad a single-digit month: find
(?<=/)(\d)(?=/\d{4}\b), replace with0$1. - Reorder: find
\b(\d{2})/(\d{2})/(\d{4})\b, replace with$3-$2-$1.
1/5/2025 becomes 01/5/2025, then 01/05/2025, then 2025-05-01. The look-aheads make sure the first two rules only touch digits that are part of a date followed by a four-digit year. A batch tool that runs stacked rules in order handles all three in one pass.
Day first or month first? Check before you convert
The pattern cannot tell 04/05/2026 (4 May) from 04/05/2026 (April 5). Before converting:
- Find out where the data came from. UK, European, Australian and most other systems write day first; US systems write month first.
- Search for dates where the first number is above 12, which proves day first:
\b(1[3-9]|2\d|3[01])/\d{2}/\d{4}\b. - Search for dates where the second number is above 12, which proves month first:
\b\d{2}/(1[3-9]|2\d|3[01])/\d{4}\b.
If both searches find matches in the same file, the file mixes formats and needs manual review.
Stricter patterns that reject impossible dates
The basic pattern accepts 99/99/2025. A stricter version only matches valid day and month numbers:
\b(0[1-9]|[12]\d|3[01])/(0[1-9]|1[0-2])/(\d{4})\b
It still accepts 31/02/2025, because checking days per month (and leap years) in regex is impractical. If invalid dates matter, validate them afterwards in a spreadsheet or script.
Dates with times attached
Timestamps such as 31/12/2025 14:30 convert with the same groups, plus one for the time:
- Find:
\b(\d{2})/(\d{2})/(\d{4}) (\d{2}:\d{2}(?::\d{2})?)\b - Replace:
$3-$2-$1T$4
The result, 2025-12-31T14:30, is the ISO 8601 date-time form that most programs and databases read without ambiguity. Use a space instead of T in the replacement if the target system prefers it. The optional (?::\d{2})? handles seconds when they are present.
Why ISO dates are worth the conversion
- They sort correctly as text. File names and lines that start with
2025-12-31sort into date order alphabetically, which DD/MM/YYYY never does. - They are unambiguous. Nobody reads
2026-04-05as May 4. - Software expects them. JSON APIs, SQL databases and most programming languages parse YYYY-MM-DD by default.
Month names
Dates written as 31 Dec 2025 need one rule per month. Twelve rules like these, run in order:
- Find
\b(\d{2}) Jan (\d{4})\b, replace with$2-01-$1 - Find
\b(\d{2}) Feb (\d{4})\b, replace with$2-02-$1 - ... and so on to December.
This is a good case for keeping the rules in a CSV. Our guide to bulk find and replace from a list shows how.
Doing it in PowerShell
For a folder of CSV files, this converts every DD/MM/YYYY date to ISO and lists the files it changed:
Get-ChildItem -Recurse -File -Filter *.csv | ForEach-Object { $t = [IO.File]::ReadAllText($_.FullName); $n = $t -replace '\b(\d{2})/(\d{2})/(\d{4})\b','$3-$2-$1'; if ($n -ne $t) { [IO.File]::WriteAllText($_.FullName, $n); $_.FullName } }
Keep the replacement in single quotes so PowerShell leaves $3 for the regex engine. WriteAllText writes UTF-8 without a byte order mark; if your files are ANSI, read and write them with Get-Content -Raw -Encoding Default and Set-Content -NoNewline -Encoding Default in Windows PowerShell 5.1 instead. Back up first, because the script has no undo.
Running the conversion across many files
- Back up the files.
- Limit the scope to the files that hold the dates: for example
.csv,.json,.xmlor.md. - Run the search only and look at the count and a sample of matches. Watch for version numbers, phone numbers or IDs that look like dates.
- Apply, then spot-check results, especially dates near the start of a month.
In Bulk Replace, the date conversion is a regex rule with capture groups, written exactly as above ($3-$2-$1). The before/after diff shows every converted date in every file, so a version number caught by mistake can be unticked before anything is written. Bulk Replace backs up every run first, and one click undoes it.
Editing CSV files at the text level avoids Excel reformatting the dates on save, which is a common way date columns get scrambled. See our regex cheat sheet for the full syntax used here.
For more on groups and the $1 syntax, read regex replace with capture groups.
Frequently asked questions
How do I tell DD/MM from MM/DD dates?
You cannot tell from a date like 04/05/2026 alone. Check where the data came from, or look for a first number above 12 in the same file to confirm the order.
What regex converts DD/MM/YYYY to YYYY-MM-DD?
Find (\d{2})/(\d{2})/(\d{4}) and replace with $3-$2-$1. Add \b at each end so it does not match inside longer numbers.
Does regex check that a date is valid?
Not easily. A simple pattern accepts 31/02/2026. Validate the dates in a program or spreadsheet if invalid values matter.
