# Can you add a script function for date processing?

**URL:** https://community.mp3tag.de/t/can-you-add-a-script-function-for-date-processing/8830
**Category:** General Discussion
**Created:** [August 22, 2009, 5:37pm UTC](https://community.mp3tag.de/t/can-you-add-a-script-function-for-date-processing/8830 "2009-08-22T17:37:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JNicoll](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/898d66/32.png) [@JNicoll](https://community.mp3tag.de/u/JNicoll)
#### Post date: [August 22, 2009, 5:37pm UTC](https://community.mp3tag.de/t/can-you-add-a-script-function-for-date-processing/8830/1 "2009-08-22T17:37:42Z")

</div>

I mainly use mp3tag for processing BBC podcasts. These typically have filenames of form

prg\_yyyymmdd.mp3

where 'prg' is a truncated version of the original radio programme's name, and the 'yyyymmdd' portion is the original radio programme's transmission date.

I've developed several quite complicated action lists where I typically copy the filename to other fields (eg 'Album' or 'Title') then manipulate the filename and whatever was originally in those fields, using a series of regex based replaces, to reset them to values I want.

Unfortunately for some BBC programmes the same 'prg' letters are used to represent programmes transmitted several times per week, in somewhat differing formats. For example in one program what's transmitted on a Sat/Sun reports on a particular problem, while in the following Wednesday's transmission there's a phone-in about a related matter.

At the moment I end up with both sorts of programme in the same 'Album' subfolder on my mp3 player because I cannot distinguish between the two types of podcast which both have the same 'prg' value in their filenames.

I'd like to be able to derive the transmission date's day name from the yyyymmdd value in the filename. If you could provde a function which, when given 'yyyymmdd' returned an integer in range 1-7 or 0-6 or whatever, this would be extremely useful.

---

<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: [August 23, 2009, 4:19am UTC](https://community.mp3tag.de/t/can-you-add-a-script-function-for-date-processing/8830/2 "2009-08-23T04:19:45Z")

</div>

> [@JNicoll](#):
>
> ... These typically have filenames of form  
> prg\_yyyymmdd.mp3  
> where 'prg' is a truncated version of the original radio programme's name, and the 'yyyymmdd' portion is the original radio programme's transmission date.  
> ... Unfortunately ... same 'prg' letters are used to represent programmes transmitted several times per week ...  
> I'd like to be able to derive the transmission date's day name from the yyyymmdd value in the filename. ...

You can use a converter funcion to split the filename into several tag fields, alternatively you may use an action "guess values".  
Here is a converter example:

 

**Convert** | **Filename - Tag** | **ALT+2**

 

_Select format string_

 

Formatstring: prg\_yyyymmdd.mp3  
**%prg\_title%\_%prg\_datetime%**

 

Preview  
**prg\_title** | prg  
**prg\_datetime** | yyyymmdd

 

Further on you may evaluate the new tag fields to make your decisions.

> [@JNicoll](#):
>
> ... If you could provde a function which, when given 'yyyymmdd' returned an integer in range 1-7 or 0-6 or whatever, this would be extremely useful.

As I understand .. you need a $weekday() function returning the weekday number in the format of ISO 8601 (1..7, monday..sunday) or american standard (0..6, sunday..saturday).  
Such a function does not exist in Mp3tag scripting language.  
I think it is not possible to calculate a weekday number by Mp3tag scripting language now.

DD.20090823.0825.CEST

---

<div class="post-metadata">

### Author: ![JNicoll](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/898d66/32.png) [@JNicoll](https://community.mp3tag.de/u/JNicoll)
#### Post date: [August 23, 2009, 12:54pm UTC](https://community.mp3tag.de/t/can-you-add-a-script-function-for-date-processing/8830/3 "2009-08-23T12:54:25Z")

</div>

> [@DetlevD](#):
>
> As I understand .. you need a $weekday() function returning the weekday number in the format of ISO 8601 (1..7, monday..sunday) or american standard (0..6, sunday..saturday).  
> Such a function does not exist in Mp3tag scripting language.

Precisely, which is why I am asking for it.

---

<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 16, 2014, 1:40pm UTC](https://community.mp3tag.de/t/can-you-add-a-script-function-for-date-processing/8830/4 "2014-03-16T13:40:35Z")

</div>

Here is a Mp3tag action script, which calculates the ISO weekday number and the ISO weekday name from a given ISO date string.

For example ... ISO Date Day-Nr Day-Name-Short Day-Name-Long

```
1954-12-01 3 Wed Wednesday
1958-10-27 1 Mon Monday
1966-02-17 4 Thu Thursday
1993-10-05 2 Tue Tuesday
2009-02-01 7 Sun Sunday    
2014-03-16 7 Sun Sunday
9999-12-31 5 Fri Friday

```

The action group expects the tag-field TMP\_ISO\_DATE filled with a correct ISO date string of format "YYYY-MM-DD".

The action group creates three new tag-fields ...

```
TMP_ISO_DAYOW number of weekday (1..7 for Monday..Sunday)
TMP_ISO_DAYNAME_L name of weekday in long version (Monday..Sunday)
TMP_ISO_DAYNAME_S name of weekday as 3-letter abbreviation (Mon..Sun)

```

Begin Action Group **Format DATE#Get DayOfWeek from ISO Date** 

Action #1  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **TMP\_ISO\_DATE**  
_Formatstring:_ **$if2(%TMP\_ISO\_DATE%,'9999-12-31')**

 

Action #2  
_Actiontype 7:_ **Import tag fields (guess values)**  
_Source format \_\_:_ **%TMP\_ISO\_DATE%**  
_Guessing pattern:_ **%TMP\_ISO\_YEAR%-%TMP\_ISO\_MONTH%-%TMP\_ISO\_DAY%**

 

Action #3  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **TMP\_ISO\_YEAR**  
_Formatstring:_ **$sub(%TMP\_ISO\_YEAR%,$if($less(%TMP\_ISO\_MONTH%,3),1,0))**

 

Action #4  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **TMP\_ISO\_DAYOW**  
_Formatstring:_ **$mod($add(%TMP\_ISO\_YEAR%,$div(%TMP\_ISO\_YEAR%,4),$div(%TMP\_ISO\_YEAR%,-100),$div(%TMP\_ISO\_YEAR%,400),$regexp(';0=0;1=3;2=2;3=5;4=0;5=3;6=5;7=1;8=4;9=6;10=2;11=4;','^._;'$sub(%TMP\_ISO\_MONTH%,1)'=(\d);._$','$1'),%TMP\_ISO\_DAY%),7)**

 

Action #5  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **TMP\_ISO\_DAYOW**  
_Formatstring:_ **$if($eql(0,%TMP\_ISO\_DAYOW%),7,%TMP\_ISO\_DAYOW%)**

 

Action #6  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **TMP\_ISO\_DAYNAME\_S**  
_Formatstring:_ **$regexp(';0=Sun;1=Mon;2=Tue;3=Wed;4=Thu;5=Fri;6=Sat;7=Sun;','^._;'%TMP\_ISO\_DAYOW%'=(\w{3});._$','$1')**

 

Action #7  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **TMP\_ISO\_DAYNAME\_L**  
_Formatstring:_ **$regexp(';0=Sunday;1=Monday;2=Tuesday;3=Wednesday;4=Thursday;5=Friday;6=Saturday;7=Su  
nday;','^._;'%TMP\_ISO\_DAYOW%'=(\w{6,9});._$','$1')**

 

Action #8  
_Actiontype 9:_ **Remove fields**  
_Fields to remove (semicolon separated):_ **TMP\_ISO\_YEAR;TMP\_ISO\_MONTH;TMP\_ISO\_DAY**

 

End Action Group **Format DATE#Get DayOfWeek from ISO Date** (8 Actions)

[Format\_DATE\_Get\_DayOfWeek\_from\_ISO\_Date.mta](https://community.mp3tag.de/uploads/default/original/2X/2/28590feb11fd4e8b3372cec0c305c94f2decf5ad.mta) (1.07 KB)  
After downloading rename the mta file to ...  
"Format DATE#Get DayOfWeek from ISO Date"

I have derived this Mp3tag solution from the methods of Sakamoto, Lachman, Keith and Craver.  
[http://en.wikipedia.org/wiki/Determination...eith\_and\_Craver](http://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Implementation-dependent_methods_of_Sakamoto.2C_Lachman.2C_Keith_and_Craver)

DD.20140316.1540.CET

[Format\_DATE\_Get\_DayOfWeek\_from\_ISO\_Date.mta](https://community.mp3tag.de/uploads/default/original/2X/2/28590feb11fd4e8b3372cec0c305c94f2decf5ad.mta) (1.07 KB)
