Generating a date from Year/Week (Day Of Week)

I have a situation where the only date related information in an MP3 tag is a
4/6 charater field (or part thereof) indicating the Year and Week number.

I would like to be able to generate an ISO Date from this information.

Example: 201107 (or 1107) represents Year: 2011 Week: 7 and of course we
would provide it with a variable (1-7) of the Day of the week e.g. Wednesday = 3.
The calculation would return 2011-02-16

I tried several approaches which on my part didn;t get me very far such as
Regex or the MP3Tag built in functions.

Can anyone suggest an approach to take,

Many thanks in advance,

Desmond.

perhaps an export to a csv-file and a subsequent treatment in Excel (or some similar) which has a set of powerful date functions.
If you google for the calender-week to date calculation, you find loads of examples.
You can then re-import the result, if you saved it in Excel as text-file.

Mp3tag does not provide an easy way for mathematical calculation or conversion from year-week-day to year-month-day date values.
But there is an easy way to solve the request by using a lookup-table.

For example ... for the ywd-value "2014221" look into the table of the year 2014 ...
and get the corresponding ymd-value "2014-05-26".

Attached is an archive file with table files for each year from "1900" to "2100".

Extract the table files from the archive file into the folder "%APPDATA%\Mp3tag\data".
By extraction there should be created the subfolder "Tables.Ywd.Ymd", which contains the various table files.

Create the action group ...

Begin Action Group Format DATE#Get ISO Date from YearWeekDaynumber

Action #1
Actiontype 14: Import text file
Field __: DATE_TABLE
Filename: $getEnv('MP3TAGAPPDATA')'\data\Tables.Ywd.Ymd<!--colorc-->'$left(%DATE_YWD%,4)'.Table.Ywd.Ymd.txt'

Action #2
Actiontype 5: Format value
Field ______: DATE_YMD
Formatstring: $regexp(%DATE_TABLE%,'^.\n'$replace(%DATE_YWD%,'W',,'-',)'\s(\d\d\d\d-\d\d-\d\d)\r.$','$1')

Action #3
Actiontype 9: Remove fields
Fields to remove (semicolon separated): DATE_TABLE

End Action Group Format DATE#Get ISO Date from YearWeekDaynumber (3 Actions)

The string format for the input tag-field "DATE_YWD" can be ...
"2014221" or "2014W221" or "2014-W22-1"

How to use it?

  1. Create the tag-field "DATE_YWD" with the value "2014221".
  2. Execute the lookup action.
  3. Check the result in the tag-field "DATE_YMD", should be "2014-05-26".

Erratum
The initially published ywd-ymd-tables were not correct, because they miss the week W53.
I have created a new set of ywd-ymd-tables, with each year containing a list of ywd values from "yyyy-W01-1" to "yyyy-W53-7".
Now each table-file contains 53 weeks with 53*7=371 ywd-values within one year.

Note: These tables are semantically not fully correct, because in some years some W53 ywd-values are not defined by the calendar system.
But this does not harm the purpose of the simple lookup tables for ywd-to-ymd conversion.
The tables are not made to validate a given ywd-value, regarding W53.

20140526.Tables.YwdToYmd.zip ( 162.86K ) Number of downloads: 1

Test_2014_20140525.YWD_to_YMD.mta ( 266bytes ) Number of downloads: 5

Tables.Ywd.Ymd.1900.2100.rar (202 KB)Format_DATE_Get_ISO_Date_from_YearWeekDay.mta (284 Bytes)

After downloading rename the mta file to ...
"Format DATE#Get ISO Date from YearWeekDay.v1.mta"

DD.20140526.1040.CEST, DD.20140526.2022.CEST, DD.20140528.1205.CEST, DD.20140530.1120.CEST

Format_DATE_Get_ISO_Date_from_YearWeekDay.mta (284 Bytes)

Tables.Ywd.Ymd.1900.2100.rar (202 KB)

Wow...Cheers...I'll give that a go !!!

Many Thanks...

Worked a charm, many thanks;
I didn't realize you could embed 'MP3TAG' functions within the search pattern of a
Regexp function...
Wonderful...

This approach now really has me thinking of othere 'little' problems I have had in the past with
importing 'releted' data.

Cheers,

Desmond.

Attached is a Mp3tag mta script, which calculates the ymd-value from the given ywd-value, without external lookup tables.

How to use it?

  1. Create the tag-field "DATE_YWD" with the value "2014221" or "2014-W221" or "2014-W22-1".
  2. Execute the action.
  3. Check the result in the tag-field "DATE_YMD", should be "2014-05-26".

Format_DATE_Get_ISO_Date_from_YearWeekDay.v2.mta (3.8 KB)

After downloading rename the mta file to ...
"Format DATE#Get ISO Date from YearWeekDay.v2.mta"

DD.20140530.1120.CEST

Format_DATE_Get_ISO_Date_from_YearWeekDay.v2.mta (3.8 KB)