# Regex expression to transform dates

**URL:** https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436
**Category:** Support
**Created:** [February 9, 2025, 6:58am UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436 "2025-02-09T06:58:08Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![GeorgeW](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c37758/32.png) [@GeorgeW](https://community.mp3tag.de/u/GeorgeW)
#### Post date: [February 9, 2025, 6:58am UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436/1 "2025-02-09T06:58:08Z")

</div>

Greetings,

I have struggled to swap the operation of this format expression

[Regular Expressions - #46 by DetlevD](https://community.mp3tag.de/t/regular-expressions/521/46)?

to achieve this

2009-02-03 to 03 Feb 2009

Would appreciate any help from regex experts

Thanks

George

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [February 9, 2025, 7:21am UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436/2 "2025-02-09T07:21:39Z")

</div>

You do not say in which field you find the date.  
Try an action of the type "Format value" or Convert\>Tag-Tag for the unnamed field  
Format string: `$regexp('2009-02-03',\d+-\d+-(\d+),$1) $replace($regexp('2009-02-03',\d+-(\d+)-\d+,$1),01,Jan,02,Feb) $regexp('2009-02-03',(\d+)-\d+-\d+,$1)`  
in which you also replace `'2009-02-03'` with the fieldname.  
And you have to complete the translation of month numbers into month names. I was too lazy to write all 12 and just showed 01 for Jan and 02 for Feb

---

<div class="post-metadata">

### Author: ![GeorgeW](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c37758/32.png) [@GeorgeW](https://community.mp3tag.de/u/GeorgeW)
#### Post date: [February 9, 2025, 7:40am UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436/3 "2025-02-09T07:40:00Z")

</div>

Thank you, I will try this. I have been using a Comment field as my experiment field, but ultimately I want to split filename (2003-03-01-SomeTextFollows) into the Title field as 01 Mar 2003 - Some Text Follows. I have managed to achieve the text extraction and conversion and am happy I can achieve the concatenation of date and text once I have converted date format.

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [February 9, 2025, 7:45am UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436/4 "2025-02-09T07:45:40Z")

</div>

I would use Convert\>Filename-Tag with  
Format string: %year% - %title%  
to get the data from the filename into the fields YEAR and TITLE  
and then use this structured data to adapt the format.  
Finally, you can re-write the filename with Convert\>Tag-Filename (if still required).  
Also, you can copy the YEAR data to TITLE with  
Convert\>Tag-Tag for TITLE  
Format string: %year% - %title%

---

<div class="post-metadata">

### Author: ![GeorgeW](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c37758/32.png) [@GeorgeW](https://community.mp3tag.de/u/GeorgeW)
#### Post date: [February 9, 2025, 8:32am UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436/5 "2025-02-09T08:32:01Z")

</div>

The final tested solution.

Convert 2009-03-02 to 2 Mar 2009

~~`$regexp(%yourfield%,\d+-\d+-(\d+),$1) $replace($regexp(%yourfield%,\d+-(\d+)-\d+,1),01,Jan,02,Feb,03,Mar,04,Apr,05,May,06,Jun,07,Jul,08,Aug,09,Sep,10,Oct,11,Nov,12,Dec) $regexp(%yourfield%,(\d+)-\d+-\d+,$1)`~~

Thank you @ohrenkino for your guidance

> [@GeorgeW](#):
>
> Could you please correct in my solution, I appear be unable to edit.

`$regexp(%yourfield%,\d+-\d+-(\d+),$1) $replace($regexp(%yourfield%,\d+-(\d+)-\d+,$1),01,Jan,02,Feb,03,Mar,04,Apr,05,May,06,Jun,07,Jul,08,Aug,09,Sep,10,Oct,11,Nov,12,Dec) $regexp(%yourfield%,(\d+)-\d+-\d+,$1)`

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [February 12, 2025, 11:24am UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436/6 "2025-02-12T11:24:09Z")

</div>

> [@GeorgeW](#):
>
> $regexp(%yourfield%,\d+-\d+-(\d+),$1) $replace($regexp(%yourfield%,\d+-(\d+)-\d+,1),01,Jan,02,Feb,03,Mar,04,Apr,05,May,06,Jun,07,Jul,08,Aug,09,Sep,10,Oct,11,Nov,12,Dec) $regexp(%yourfield%,(\d+)-\d+-\d+,$1)

Are you sure that this should work as expected?

If I try it with 2009-03-02 in a COMMENT field and this regular expression:  
`$regexp(%COMMENT%,\d+-\d+-(\d+),$1) $replace($regexp(%COMMENT%,\d+-(\d+)-\d+,1),01,Jan,02,Feb,03,Mar,04,Apr,05,May,06,Jun,07,Jul,08,Aug,09,Sep,10,Oct,11,Nov,12,Dec) $regexp(%COMMENT%,(\d+)-\d+-\d+,$1)`  
I get as result `02 1 2009` and not the expected `2 Mar 2009`

 ![image](https://community.mp3tag.de/uploads/default/original/3X/e/c/ecefb041abcebace5ae875b4cec53f499c76b048.png)

Even If I fix the replacement from `01,Jan` to `1,Jan` I only get `02 Jan 2009` as result.

BTW:  
The regular expression started from @ohrenkino would work for the March example:  
`$regexp(%COMMENT%,\d+-\d+-(\d+),$1) $replace($regexp(%COMMENT%,\d+-(\d+)-\d+,$1),01,Jan,02,Feb,03,Mar) $regexp(%COMMENT%,(\d+)-\d+-\d+,$1)` and results in the expected `02 Mar 2009`  
(please note the leading zero for the day)

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [February 12, 2025, 11:32am UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436/7 "2025-02-12T11:32:50Z")

</div>

This regular expression would work - at least for the number-to-month replacement.  
`$regexp(%COMMENT%,\d+-\d+-(\d+),$1) $replace($regexp(%COMMENT%,\d+-(\d+)-\d+,$1),01,Jan,02,Feb,03,Mar,04,Apr,05,May,06,Jun,07,Jul,08,Aug,09,Sep,10,Oct,11,Nov,12,Dec) $regexp(%COMMENT%,(\d+)-\d+-\d+,$1)`

But it still convert YYYY-MM-DD in DD MMM YYYY (with a leading zero in front of the day).  
`2009-03-02` becomes `02 Mar 2009`

If the expected result should show the days 01 to 09 without leading zero, then you would need an additional `$num` around the number of days, something like  
`$num($regexp(%COMMENT%,\d+-\d+-(\d+),$1),1)`...

The complete regular expression to

> [@GeorgeW](#):
>
> Convert 2009-03-02 to 2 Mar 2009

would look like this:  
`$num($regexp(%COMMENT%,\d+-\d+-(\d+),$1),1) $replace($regexp(%COMMENT%,\d+-(\d+)-\d+,$1),01,Jan,02,Feb,03,Mar,04,Apr,05,May,06,Jun,07,Jul,08,Aug,09,Sep,10,Oct,11,Nov,12,Dec) $regexp(%COMMENT%,(\d+)-\d+-\d+,$1)`

---

<div class="post-metadata">

### Author: ![GeorgeW](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c37758/32.png) [@GeorgeW](https://community.mp3tag.de/u/GeorgeW)
#### Post date: [February 12, 2025, 9:45pm UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436/8 "2025-02-12T21:45:45Z")

</div>

@LyricsLover

Apologies, you are right, there is a missing $ here, for the 1 variable at end of this string.

$regexp(%year%,\d+-\d+-(\d+),$1) $replace($regexp(%year%,\d+-(\d+)-\d+,$1) ....

Could you please correct in my solution, I appear be unable to edit.

---

<div class="post-metadata">

### Author: ![GeorgeW](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c37758/32.png) [@GeorgeW](https://community.mp3tag.de/u/GeorgeW)
#### Post date: [February 12, 2025, 9:49pm UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436/9 "2025-02-12T21:49:26Z")

</div>

@LyricsLover

Agree that my expression does not remove leading zero for single digit day values, but I didn't see that as an issue, was so happy to achieve transformation 😄

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [February 12, 2025, 10:42pm UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436/10 "2025-02-12T22:42:00Z")

</div>

> [@GeorgeW](#):
>
> Could you please correct in my solution, I appear be unable to edit.

I'm not sure why you are unable to click on the  
 ![image](https://community.mp3tag.de/uploads/default/original/3X/5/6/56f35aff12746859701da730ab5c4d4ea57c06a9.png)  
icon and edit your own solution.  
But I hope I have fixed it (please double check it).

> [@GeorgeW](#):
>
> but I didn't see that as an issue

This is not a big issue, I have only added this version for future readers.

---

<div class="post-metadata">

### Author: ![GeorgeW](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c37758/32.png) [@GeorgeW](https://community.mp3tag.de/u/GeorgeW)
#### Post date: [February 12, 2025, 11:09pm UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436/11 "2025-02-12T23:09:41Z")

</div>

Editing of Solution not allowed? I don't see the pencil symbol on my Solution post, but I do see it on my other posts in this thread.

Solution is correct now, thank you

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [March 14, 2025, 11:10pm UTC](https://community.mp3tag.de/t/regex-expression-to-transform-dates/67436/12 "2025-03-14T23:10:10Z")

</div>

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