Converting my dd-mm-yyy date: YAML format to ISO8601 using VS Code - please help

What I’m trying to do

I recently realised why my dataview queries weren’t pulling notes based on dates, because my template dates all format as:

So, I need to re-order my date: YAML headings, retaining the date information, but making it conform to ISO8601.

I’m not a coder, but I have VS code installed and have watched ‘DeeConforms’ and others on YouTube demonstrate a ‘find and replace’ function, where the existing information is deleted and replaced with new information.

This isn’t exactly what I want to do because I want to keep the date information, just re-order it.

Things I have tried

Reading these threads:

I see that the solution is backing up my notes and using VS code to reformat the dates.

I’ve seen videos of doing simple ‘find+replace’ functions, but this is more of a ‘re-order’ function.
move dd-mm-yyyy to yyyy-mm-dd
(or whatever the best IOS8601 format is)

I’d like to retain the date information.

My ask for help

Please could someone point me to how to do this in VS code?
Or, where I should be looking for find how to do this?
Or, has someone had to do this re-order process for themselves and can share the code?

I have 2,000+ notes in my vault

Matching dates using regex can be a rabbit hole of dimension, and even though the simplest case of doing something like: (\d{2})-(\d{2})-(\d{4}) would work in a lot of cases, especially when doing this match against a larger data set I would prefer using something slightly more specific, to avoid changing some non-dates into garbage.

For an extensive discussion related to regex and dates, see regex - Regular Expression to match valid dates - Stack Overflow

So my variant would be something like:

Find: (0[1-9]|[12]\d|30|31)-(0[1-9]|1[0-2])-([12]\d{3})
Replace: $3-$2-$1
Some test cases

See regex101: build, test, and debug regex for a demonstration of this regex.

Test cases, with some valid(?) dates in the first part, and some invalid in the latter part:

29-02-1973 (not a leap year, or valid date!!)


Note how that this regex wrongfully accepts Feb 29th 1973 as a valid date, even though that wasn’t a leap year. However, it doesn’t accept outside of the “normal” date ranges, that is 01 through 12 for month, 01 through 31 for days, and 1000 through 2999 for years.

To use this expression within VS Code you need to open the folder with your vault in it, and open the search-and-replace window, and set the following options:

  • Enter the find and replace expression from above
  • Enable the regex search option, that is the .* icon, at the end of the find line
  • (If you don’t see the four lines hit the ellipsis to expand the search option in the lower right part (shown in the middle of the image on the right)
  • Enter * in files to include
  • Make sure the icon for search only in open files are disabled (at the end of the files to include line)
  • Enter .obsidian/*in files to exclude (to avoid changing stuff within the system settings and so on

So it should resemble something like this:

When the search has completed, I would review some of the result that they actually make sense, before either replacing some of the manually, and verifying correct changes, or before hitting the Replace all icon at the end of the replace line (under the regex search icon, .*)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.