# Format value always most recent year from selected

**URL:** https://community.mp3tag.de/t/format-value-always-most-recent-year-from-selected/64435
**Category:** Support
**Created:** [April 17, 2024, 10:44am UTC](https://community.mp3tag.de/t/format-value-always-most-recent-year-from-selected/64435 "2024-04-17T10:44:17Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Vadim](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/v/50afbb/32.png) [@Vadim](https://community.mp3tag.de/u/Vadim)
#### Post date: [April 17, 2024, 10:44am UTC](https://community.mp3tag.de/t/format-value-always-most-recent-year-from-selected/64435/1 "2024-04-17T10:44:17Z")

</div>

Hello

So, for each artist, where relevant, I have created a folder containing all singles released formatted as such:

Field:  
\_DIRECTORY

Format string:  
$num(%year%,4) - %album%

If there are multiple singles with varying year, and I run my Action to format string, I can't figure out which year value it converts to. It seems random amongst the songs selected.  
But I always want the format string to output the most recent year from the tags on the selected files.

Is there a way to do this?

So far I've manually picked the most recent song and just run the action again.  
But this way it'll take forever to format my entire music library folders.  
If I run my current action most of the "singles albums" will get the wrong year value.

Cheers!

---

<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: [April 17, 2024, 10:58am UTC](https://community.mp3tag.de/t/format-value-always-most-recent-year-from-selected/64435/2 "2024-04-17T10:58:41Z")

</div>

> [@Vadim](#):
>
> I can't figure out which year value it converts to. It seems random amongst the songs selected.

I think it is the last file.  
So: sort by YEAR and then run the action.

---

<div class="post-metadata">

### Author: ![Vadim](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/v/50afbb/32.png) [@Vadim](https://community.mp3tag.de/u/Vadim)
#### Post date: [April 21, 2024, 6:53pm UTC](https://community.mp3tag.de/t/format-value-always-most-recent-year-from-selected/64435/3 "2024-04-21T18:53:59Z")

</div>

Hmm, just tried with a folder containing 6 songs from different years (2019, 2019, 2020, 2022, 2023, 2024).  
If I sort by Year (most recent to oldest --\> most recent at the top) and run the command multiple times it'll change between 2024 and 2023 reliably it seems.  
So for my case it's still too unreliable to format my entire library at once.

---

<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: [April 21, 2024, 7:35pm UTC](https://community.mp3tag.de/t/format-value-always-most-recent-year-from-selected/64435/4 "2024-04-21T19:35:53Z")

</div>

Yes, I could reproduce that if you execute out that action several times.

I tried Convert\>tag-Tag for \_DIRECTORY with  
Format string: `$if($less($regexp(%_directory%,.* (\d+),$1),%year%),%album% - %year%,%_directory%)`  
and a sorted list where the youngest year (2024) was at the top and it reproduceably took that year, in this case 2024.

---

<div class="post-metadata">

### Author: ![Vadim](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/v/50afbb/32.png) [@Vadim](https://community.mp3tag.de/u/Vadim)
#### Post date: [April 21, 2024, 8:16pm UTC](https://community.mp3tag.de/t/format-value-always-most-recent-year-from-selected/64435/5 "2024-04-21T20:16:52Z")

</div>

Thanks a bunch! This doesn't even seem to be necessary to sort. It'll automatically pick the most recent year regardless of sorting in ascending or descending order.

I'm not great at this, so it took me a couple of tries. But here's the method for others:  
Actions --\> Actions --\> New --\> Pick a name for the action --\> New --\> Format Value --\> Field: \_DIRECTORY --\> Format string: $if($less($regexp(%\_directory%,.\* (\d+),$1),%year%),%album% - %year%,%\_directory%)

---

<div class="post-metadata">

### Author: ![Vadim](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/v/50afbb/32.png) [@Vadim](https://community.mp3tag.de/u/Vadim)
#### Post date: [April 22, 2024, 8:17pm UTC](https://community.mp3tag.de/t/format-value-always-most-recent-year-from-selected/64435/6 "2024-04-22T20:17:07Z")

</div>

Hello again

Just stumbled upon an entire album where the year of all songs are formatted as follows:  
"2022-10-14".  
With your format string the directory changes name to "Darkbloom - 2022-10-14".

I have no idea why the %album% and %year% changed place. And neither why it's including month and date. I only need the year.

---

<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: [April 22, 2024, 8:25pm UTC](https://community.mp3tag.de/t/format-value-always-most-recent-year-from-selected/64435/7 "2024-04-22T20:25:02Z")

</div>

> [@Vadim](#):
>
> I only need the year.

If

> [@Vadim](#):
>
> 2022-10-14

is the string in YEAR then the referenced %year% takes all that is found in YEAR.  
Instead of the plain %year% use $num(%year%,1)

---

<div class="post-metadata">

### Author: ![Vadim](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/v/50afbb/32.png) [@Vadim](https://community.mp3tag.de/u/Vadim)
#### Post date: [April 24, 2024, 5:34am UTC](https://community.mp3tag.de/t/format-value-always-most-recent-year-from-selected/64435/8 "2024-04-24T05:34:11Z")

</div>

Once again, thank you!  
Works like a charm from my quick testing.  
Cheers.

---

<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: [May 24, 2024, 5:34am UTC](https://community.mp3tag.de/t/format-value-always-most-recent-year-from-selected/64435/9 "2024-05-24T05:34:52Z")

</div>

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