# Tag Action Formatting Rule Expression/Function Question

**URL:** https://community.mp3tag.de/t/tag-action-formatting-rule-expression-function-question/9692
**Category:** General Discussion
**Created:** [January 12, 2010, 4:59pm UTC](https://community.mp3tag.de/t/tag-action-formatting-rule-expression-function-question/9692 "2010-01-12T16:59:53Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![edrikk](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/e/c37758/32.png) [@edrikk](https://community.mp3tag.de/u/edrikk)
#### Post date: [January 12, 2010, 4:59pm UTC](https://community.mp3tag.de/t/tag-action-formatting-rule-expression-function-question/9692/1 "2010-01-12T16:59:53Z")

</div>

Hi,

I've got a number of actions setup within MP3Tag, and all is working well.

I do have on action which is to work on the "YEAR" atom (of an MP4 file), but which seems to constantly give me a result which is not what I expect.

I think a second set of eyes would help here:

Here is my action rule/function for the "YEAR" atom:

```
$if($len($trim(%year%)) >= 4,$left(%year%,4)-01-01T12:00:00,%year%)

```

My expected behavior is that: If the length of the "year" atom is greater than or equal to 4, the year atom should concatenate "-01-01T12:00:00" to the first 4 characters of the existing "year" atom. If the length is less than 4, keep the year atom as is.

However, when I run this rule, although the result of the length function is correctly calculated, I always seem to go into the concatenation (ie "true") rule (which does work)... the "else" rule never seems to get fired...

Does anyone see anything obvious that I've messed up?

This is strange, because I have a similar rule for my "ALBUM" atom, which works perfectly:

```
$if($len($trim(%album%)) > 0,$if($eql(%album%,%title%),%title%,%album%),%title%)

```

(If the album atom is empty, or if it has a value equal to title atom, put title atom's value in it. Otherwise, leave it as is.)

---

<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 12, 2010, 5:34pm UTC](https://community.mp3tag.de/t/tag-action-formatting-rule-expression-function-question/9692/2 "2010-01-12T17:34:32Z")

</div>

> [@edrikk](#):
>
> ... $if($len($trim(%year%)) \>= 4,$left(%year%,4)-01-01T12:00:00,%year%) ...

I've just stopped at this line and did not read further on.  
Please have a look into Mp3tag scripting function help section and find out the fitting functions to use.

DD.20100112.1934.CET

---

<div class="post-metadata">

### Author: ![edrikk](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/e/c37758/32.png) [@edrikk](https://community.mp3tag.de/u/edrikk)
#### Post date: [January 12, 2010, 7:35pm UTC](https://community.mp3tag.de/t/tag-action-formatting-rule-expression-function-question/9692/3 "2010-01-12T19:35:16Z")

</div>

> [@DetlevD](#):
>
> I've just stopped at this line and did not read further on.  
> Please have a look into Mp3tag scripting function help section and find out the fitting functions to use.
> 
> DD.20100112.1934.CET

If you know/see what is wrong, it would be "nice" of you to just say it... Or at least say WHICH of the functions you see a problem with. It is not as if I just hit an issue, and the first thing I did was post asking for help.

$if($len($trim(%year%)) \>= 4,$left(%year%,4)-01-01T12:00:00,%year%)

Broken down, the above is:

if (Length of trimmed %year% is \>= 4)  
{  
return ((first four char of %year%) concatenated with -01-01T12:00:00)  
}  
else  
{  
return (%year%)  
}

Functions used:

$if(x,y,z) if x is true, y is returned, otherwise z.  
$len(x) Returns the length of string x.  
$trim(x) trims all leading and trailing whitespaces from the string x.  
$left(x,n) Leftmost n characters of text x.

If you don't want to help, please don't. If you see something wrong (and it could be obvious), at least give a hint. I'm a former C++,C, Java, PowerBuilder, COBOL, Shell programmer, and now lead systems designer/PM. I know what I'm doing, but I'm not too humble to ask.

Again, I'm sure I missed something obvious. RTFM was already done.

---

<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 12, 2010, 8:01pm UTC](https://community.mp3tag.de/t/tag-action-formatting-rule-expression-function-question/9692/4 "2010-01-12T20:01:08Z")

</div>

> [@edrikk](#):
>
> ... say WHICH of the functions you see a problem with. ... I know what I'm doing, but I'm not too humble to ask. ...

It seems to me that you did not look too hard into the syntax documentation of the Mp3tag scripting language, so please look at the comparison operator you've used.

DD.20100112.2201.CET

---

<div class="post-metadata">

### Author: ![edrikk](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/e/c37758/32.png) [@edrikk](https://community.mp3tag.de/u/edrikk)
#### Post date: [January 12, 2010, 9:07pm UTC](https://community.mp3tag.de/t/tag-action-formatting-rule-expression-function-question/9692/5 "2010-01-12T21:07:49Z")

</div>

> [@DetlevD](#):
>
> It seems to me that you did not look too hard into the syntax documentation of the Mp3tag scripting language, so please look at the comparison operator you've used.
> 
> DD.20100112.2201.CET

It seems to me that there is a stick firmly planted up your .....

At any rate. Got it. Thanks for your ever so generous pointer.

Thanks,

---

<div class="post-metadata">

### Author: ![edrikk](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/e/c37758/32.png) [@edrikk](https://community.mp3tag.de/u/edrikk)
#### Post date: [January 12, 2010, 9:24pm UTC](https://community.mp3tag.de/t/tag-action-formatting-rule-expression-function-question/9692/6 "2010-01-12T21:24:28Z")

</div>

btw. IF you had bothered to read my second example, you would have noticed that I used the proper syntax there... When it's a simple slip of the mind (meaning using a programming languages syntax in one part in error), a little helpfulness and kindness goes a long way.

At the end of the day, I know 3 people on this forum now:  
Florian: Awesome and helpful.  
Dano: Knowledgable, and willing to help.

You: Dick.

---

<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 12, 2010, 9:40pm UTC](https://community.mp3tag.de/t/tag-action-formatting-rule-expression-function-question/9692/7 "2010-01-12T21:40:49Z")

</div>

> [@edrikk](#):
>
> ... you would have noticed that I used the proper syntax there...

Not likely.

> [@edrikk](#):
>
> ... When it's a simple slip of the mind (meaning using a programming languages syntax in one part in error), a little helpfulness and kindness goes a long way. ...

An outstanding programmer needs not so much help like a beginner.

> [@edrikk](#):
>
> ... At the end of the day, I know 3 people on this forum now: Florian: Awesome and helpful. Dano: Knowledgable, and willing to help. You: Dick.

Congratulations for the discovery!  
It has proved once again that all that what one has ever learned is in some moments worth nothing.

DD.20100112.2340.CET

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [January 12, 2010, 9:51pm UTC](https://community.mp3tag.de/t/tag-action-formatting-rule-expression-function-question/9692/8 "2010-01-12T21:51:44Z")

</div>

I think we can stop now.
