# 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:** 1
**Showing post:** 4

<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)

---

_[View the full topic](https://community.mp3tag.de/t/can-you-add-a-script-function-for-date-processing/8830)._
