# Extracting year regardless of date format

**URL:** https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517
**Category:** Support
**Created:** [January 18, 2015, 1:04pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517 "2015-01-18T13:04:58Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Quisquose](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/q/ea666f/32.png) [@Quisquose](https://community.mp3tag.de/u/Quisquose)
#### Post date: [January 18, 2015, 1:04pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/1 "2015-01-18T13:04:58Z")

</div>

I've been using _Format String: $left(%year%,4)_ to clean up my Year field, but is there a better action that could locate 4 consecutive digits in the YEAR tag (regardless of where they are located within the string) and then use just those 4 consecutive digits as the year (deleting all other characters from the field).

This would allow the year to be extracted regardless of how the date has been formatted.

Thanks.

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [January 18, 2015, 1:40pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/2 "2015-01-18T13:40:40Z")

</div>

> [@Quiquose](#):
>
> ... is there a better action that could locate 4 consecutive digits in the YEAR tag (regardless of where they are located within the string) ...

Action: "Format value"  
Field: YEAR\_4D  
Formatstring: `$regexp(%YEAR%,'^.*(\d\d\d\d).*$','$1')`

DD.20150118.1540.CET

---

<div class="post-metadata">

### Author: ![Quisquose](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/q/ea666f/32.png) [@Quisquose](https://community.mp3tag.de/u/Quisquose)
#### Post date: [January 18, 2015, 2:25pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/3 "2015-01-18T14:25:48Z")

</div>

Thank you so much, DetlevD.

That works perfectly.

---

<div class="post-metadata">

### Author: ![hypersucker](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/h/ac8455/32.png) [@hypersucker](https://community.mp3tag.de/u/hypersucker)
#### Post date: [March 21, 2018, 2:23pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/4 "2018-03-21T14:23:19Z")

</div>

too stupid to get that to work....

I do: Actions, Action Group, New (give it a name), Select Action Type Format Value, Field: YEAR, Format String: $regexp(%YEAR%,'^.(\d\d\d\d).$','$1')

It does not work, the YEAR field stays 2017-02-02 after I applied the action.

---

<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: [March 21, 2018, 4:33pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/5 "2018-03-21T16:33:17Z")

</div>

Everything up to

> [@hypersucker](#):
>
> String: $regexp(%YEAR%,'^.(\d\d\d\d).$','$1')  
> It does not work, the YEAR field stays 2017-02-02 after I applied the action.

looks allright to me but you could try as  
Format string: `$num(%year%,1)`  
This takes the first number up to the first separator character.

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [March 21, 2018, 4:55pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/6 "2018-03-21T16:55:49Z")

</div>

It looks like as the quoted article has been changed when transferring to this new forum.

Several star characters have been lost in the regular expression.  
Probably it has been written before like this:

`Format string: $regexp(%YEAR%,'^.*(\d\d\d\d).*$','$1')`

This forum software is annoying.  
So far, I have not discovered any improvement, only worsening.  
Sorry to say this.

DD.20180321.1803.CET

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [March 21, 2018, 5:09pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/7 "2018-03-21T17:09:23Z")

</div>

Thanks, Detlev. I've fixed the string in the OP.

---

<div class="post-metadata">

### Author: ![hypersucker](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/h/ac8455/32.png) [@hypersucker](https://community.mp3tag.de/u/hypersucker)
#### Post date: [March 21, 2018, 5:17pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/8 "2018-03-21T17:17:40Z")

</div>

Danke an beide! Both work now but apperently it is possible to have multiple same-tag attributes in one file. Some of my flacs have 2 Year tags (looks like this in tag panel 2017\2017-11-24) - is there a way to include this occurence in a format string? also, this does show as 2017 in column view, not as both date formats (not that it’s a bad thing but it makes detecting such formatted tags rather difficult).

---

<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: [March 21, 2018, 5:31pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/9 "2018-03-21T17:31:17Z")

</div>

> [@hypersucker](#):
>
> apperently it is possible to have multiple same-tag attributes in one file.

If you suspect that you have multi-value fields (several fields of the same type) then modify the column definition for "Value", e.g. for YEAR:  
Instead of the plain %year% use  
`$meta_sep(year,\\)`

---

<div class="post-metadata">

### Author: ![hypersucker](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/h/ac8455/32.png) [@hypersucker](https://community.mp3tag.de/u/hypersucker)
#### Post date: [March 21, 2018, 5:39pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/10 "2018-03-21T17:39:09Z")

</div>

omg it works! dankeschön

---

<div class="post-metadata">

### Author: ![hypersucker](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/h/ac8455/32.png) [@hypersucker](https://community.mp3tag.de/u/hypersucker)
#### Post date: [March 21, 2018, 5:57pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/11 "2018-03-21T17:57:34Z")

</div>

In column view that is. Any way I can put that variable (2 values) in the regex so it will kill all but the year number?

---

<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: [March 21, 2018, 6:01pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/12 "2018-03-21T18:01:08Z")

</div>

I think you can use  
`$regexp($meta(YEAR),'^.*(\d\d\d\d).*$','$1')`  
or  
`$num($meta(YEAR),4)`

---

<div class="post-metadata">

### Author: ![hypersucker](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/h/ac8455/32.png) [@hypersucker](https://community.mp3tag.de/u/hypersucker)
#### Post date: [March 21, 2018, 6:20pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/13 "2018-03-21T18:20:34Z")

</div>

they both dont change the value in YEAR at all ☹

---

<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: [March 21, 2018, 6:36pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/14 "2018-03-21T18:36:00Z")

</div>

Yes, sorry, this treats only the contents of the first entry.  
Use  
`$num($meta(YEAR),4)\\`  
which deletes the second field as it enters a null-string for that field.

---

<div class="post-metadata">

### Author: ![hypersucker](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/h/ac8455/32.png) [@hypersucker](https://community.mp3tag.de/u/hypersucker)
#### Post date: [March 21, 2018, 7:20pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/15 "2018-03-21T19:20:39Z")

</div>

works fabulously! thanks!

---

<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: [February 9, 2026, 12:25pm UTC](https://community.mp3tag.de/t/extracting-year-regardless-of-date-format/16517/16 "2026-02-09T12:25:28Z")

</div>


