# Turn D/M/YYYY into YYYY/MM/DD

**URL:** https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074
**Category:** Export
**Created:** [October 3, 2009, 10:09am UTC](https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074 "2009-10-03T10:09:41Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![supertagger](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@supertagger](https://community.mp3tag.de/u/supertagger)
#### Post date: [October 3, 2009, 10:09am UTC](https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074/1 "2009-10-03T10:09:41Z")

</div>

Hi everyone,

I am trying to create a list of albums in txt mode, one line per album with the date-modified date in the front, like this:

2009-9-8 Electronica - Daft Punk - Homework

My script:

```
$filename(albums-only.txt)
$loop(%_folderpath%,1)$regexp(%_file_mod_date%,(\d{1,2})/(\d{1,2})/(\d{4}),$3-$1-$2) %genre% - $if2(%albumartist%,%artist) - %album% '['$replace(%_codec%,Free Lossless Audio Codec,FLAC)']'
$loopend()

```

I tried to use the "iflonger" as well as the "ifgreater" function inside the regexp function, but that does not seem to work. How can I have a ZERO precede all those days and months that are less than "less than 10".

Result should be:

2009-09-08....

as well as

2009-10-22 and not 2009-010-022

If anyone knows how to do this, please let me know!

Thank you. 🙂

---

<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: [October 3, 2009, 12:07pm UTC](https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074/2 "2009-10-03T12:07:40Z")

</div>

> [@supertagger](#):
>
> ... How can I have a ZERO precede all those days and months that are less than "less than 10".  
> Result should be: 2009-09-08.... as well as 2009-10-22 and not 2009-010-022 ...

Hmm ... my computer regional setting is "Deutsch (Deutschland)" and my short date setting is "JJJJ-MM-TT" accordingly to ISO 8601.  
Therefore Mp3tag's system variable %\_file\_mod\_date% returns 2009-10-03 and I can use it without any additionally scripting modification.

Try this export script ...

```
$filename(o:\test\20091003.supertagger.txt)
$loop(%_folderpath%,1)%album%
'1:'%_file_mod_date%
'2:'$regexp(%_file_mod_date%,'(\d{4}).(\d{1,2}).(\d{1,2})','$1=$2=$3')
'3:'$num($regexp(%_file_mod_date%,'(\d{4}).(\d{1,2}).(\d{1,2})',$3),2)
'4:'$num($regexp(%_file_mod_date%,'(\d{4}).(\d{1,2}).(\d{1,2})',$2),2)
'5:'$num($regexp(%_file_mod_date%,'(\d{4}).(\d{1,2}).(\d{1,2})',$1),4)
$loopend()

```

... and see what results do you get.

DD.20091003.1607.CEST

---

<div class="post-metadata">

### Author: ![supertagger](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@supertagger](https://community.mp3tag.de/u/supertagger)
#### Post date: [October 3, 2009, 12:51pm UTC](https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074/3 "2009-10-03T12:51:47Z")

</div>

Thank you Detlev,

that helped - I figured it out and it should work this way:

```
$num($regexp(%_file_mod_date%,'(\d{1,2}).(\d{1,2}).(\d{4})',$3),2)-$num($regexp(%_file_mod_date%,'(\d{1,2}).(\d{1,2}).(\d{4})',$1),2)-$num($regexp(%_file_mod_date%,'(\d{1,2}).(\d{1,2}).(\d{4})',$2),2)

```

This yields

```
2009-09-08 Electronic - Daft Punk - Homework

```

from what once was

```
9/8/2009

```

Thank you! 🙂

---

<div class="post-metadata">

### Author: ![supertagger](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@supertagger](https://community.mp3tag.de/u/supertagger)
#### Post date: [October 3, 2009, 1:07pm UTC](https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074/4 "2009-10-03T13:07:49Z")

</div>

Okay, only problem is now that I cannot sort inversely - or at least it seems a bit too confusing for me. Sorting normally works fine now, but the latest date will end up way down on the bottom of the list. When using $loop($sub...)) it ends up as shown below.

```
$filename(albums-only.txt)
$loop($sub(%_folderpath%,10000000000))$loop(%_folderpath%,1)$num($regexp(%_file_mod_date%,'(\d{1,2}).(\d{1,2}).(\d{4})',$3),2)-$num($regexp(%_file_mod_date%,'(\d{1,2}).(\d{1,2}).(\d{4})',$1),2)-$num($regexp(%_file_mod_date%,'(\d{1,2}).(\d{1,2}).(\d{4})',$2),2) %genre% - $if2(%albumartist%,%artist) - %album% '['$replace(%_codec%,Free Lossless Audio Codec,FLAC)']'
$loopend()$loopend()

```

Yields...

```
2009-10-02 Pop/Rock - Artist A - Album B [FLAC]
2009-09-03 Pop/Rock - Artist C - Album D [FLAC]
2009-09-03 Pop/Rock - Artist C - Album E [FLAC]
2009-09-03 Soundtrack - Artist A - Album T [FLAC]
2009-09-07 Soundtrack - Artist C - Album F [FLAC]
2009-09-08 Electronic - Artist D - Album E [FLAC]

```

Seems to be the same problem with how the date is displayed internally - how would I fix this looping inversely $loop($sub...))? Any idea? 🙂

Thank you.

---

<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: [October 3, 2009, 2:54pm UTC](https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074/5 "2009-10-03T14:54:10Z")

</div>

> [@supertagger](#):
>
> ... Okay, only problem is now that I cannot sort inversely ...

I think ... for the latest date at the top you need a formula like this ...  
$sub(10000000000,%\_file\_mod\_datetime\_raw%)

DD.20091003.1854.CEST

---

<div class="post-metadata">

### Author: ![supertagger](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@supertagger](https://community.mp3tag.de/u/supertagger)
#### Post date: [October 3, 2009, 3:33pm UTC](https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074/6 "2009-10-03T15:33:11Z")

</div>

> [@DetlevD](#):
>
> I think ... for the latest date at the top you need a formula like this ...  
> $sub(10000000000,%\_file\_mod\_datetime\_raw%)
> 
> DD.20091003.1854.CEST

Thank you for your kind help. Since I am only listing albums this does not work, as it ends up showing me multiple lines for albums depending on the minute a file in there was changed, I guess. Is there any way to use the output generated by the regexp (2009-09-22 etc.) for sorting?

Thank you. ![:huh:](https://community.mp3tag.de/uploads/default/original/1X/f15ee73c0fd9ec3b0db7481f0558638f8ee224ce.gif ":huh:")

---

<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: [October 3, 2009, 3:46pm UTC](https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074/7 "2009-10-03T15:46:30Z")

</div>

> [@supertagger](#):
>
> ... it ends up showing me multiple lines for albums depending on the minute a file in there was changed, I guess. ...

Maybe ...

- try a loop like $loop(%album%,1)
- try a formula like $div($sub(10000000000,%\_file\_mod\_datetime\_raw%),3600)
- try a formula like $div($sub(10000000000,%\_file\_create\_datetime\_raw%),3600)

DD.20091003.1955.CEST

---

<div class="post-metadata">

### Author: ![supertagger](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@supertagger](https://community.mp3tag.de/u/supertagger)
#### Post date: [November 16, 2009, 9:36am UTC](https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074/8 "2009-11-16T09:36:33Z")

</div>

Alright, I thought I would post what I ended up with - I am quite pleased with this export config. Some problems popped up when using the RAW datetime: for example, if an album gets tagged at 1am of day 1 and another at 9pm of the same day, the RAW times are too far apart to allow for proper sorting. So what I did was generate an 8-digit number by pulling together YYYY-MM-DD to YYYYMMDD. This gets subtracted and from 10000000000 and allows for proper reverse sorting.

Sample script right here:

```
$filename(whateveryouwant.txt)
                                                        
List created %_datetime%

$loop($sub(10000000000,$num($regexp(%_file_mod_date%,'(\d{1,2}).(\d{1,2}).(\d{4})',$3),2)$num($regexp(%_file_mod_date%,'(\d{1,2}).(\d{1,2}).(\d{4})',$1),2)$num($regexp(%_file_mod_date%,'(\d{1,2}).(\d{1,2}).(\d{4})',$2),2)))$loop(%albumartist%)$loop(%album%,1)$num($regexp(%_file_mod_date%,'(\d{1,2}).(\d{1,2}).(\d{4})',$3),2)-$num($regexp(%_file_mod_date%,'(\d{1,2}).(\d{1,2}).(\d{4})',$1),2)-$num($regexp(%_file_mod_date%,'(\d{1,2}).(\d{1,2}).(\d{4})',$2),2) '['%genre%']' $if2(%albumartist%,%artist) '/' %album% '('%year%')' '['$replace(%_codec%,Free Lossless Audio Codec,FLAC)']'
$loopend()$loopend()$loopend()

```

Again, thanks for all the help - maybe this helps someone also trying to reverse-sort! 🙂

---

<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: [February 15, 2011, 7:49am UTC](https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074/9 "2011-02-15T07:49:55Z")

</div>

Yes, this is a rather old thread, but it is worth to demonstrate a simplification for converting MDY date to YMD date.

The given **MDY** date (Month/Day/Year) should be a valid MDY value and can be of format ...  
02/01/2009  
02/1/2009  
2/01/2009  
2/1/2009  
02/01/0009  
02/01/09  
02/01/9  
02/1/09  
02/1/9  
2/01/9  
2/1/09  
2/1/9  
... that means the year must be a 1- or 2- or 4-digit year, the month and day values must have 1- or 2-digits.

The result is a **YMD** (Year-Month-Day) date of format ...  
2009-02-01  
... that means, the year will be always a 4-digit year, the month and day values have always a 2-digit format, zero padded at the left side, if needed.  
A given 1- or 2-digit year will not be automatically left padded with a century value (what century should be valid?), so that a given year of "9" or "09" will be padded to "0009".

 **$regexp($regexp(%DATE\_MDY%,'(\d\d?)/(\d\d?)/((?:\d\d?)(?:\d\d)?)','0000$3-00$1-00$2'),'0\*(\d\d\d\d)-0\*(\d\d)-0\*(\d\d)','$1-$2-$3')** 

DD.20110215.0952.CET

---

<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: [September 26, 2014, 8:27am UTC](https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074/10 "2014-09-26T08:27:46Z")

</div>

> [@supertagger](#):
>
> ... the RAW times are too far apart to allow for proper sorting. So what I did was generate an 8-digit number by pulling together YYYY-MM-DD to YYYYMMDD. This gets subtracted and from 10000000000 and allows for proper reverse sorting. ... maybe this helps someone also trying to reverse-sort!

Here is a shorter script with the same purpose, ...  
sort by Date modified reverse, Albumartist or Artist, Album.

**1: $filename($getEnv('USERPROFILE')'\Desktop\Mp3tag.List.Album.DateModReverse.txt',UTF-8)'List created '%\_datetime%** 

**2: $loop($sub(4000000,$div(%\_file\_mod\_datetime\_raw%,86400)))$loop($if2(%ALBUMARTIST%,%ARTIST%))$loop(%ALBUM%,1)  
3: %\_file\_mod\_date%' ['%GENRE%'] '$if2(%ALBUMARTIST%,%ARTIST%)' / '%ALBUM%' ('%YEAR%') ['$replace(%\_codec%,'Free Lossless Audio Codec','FLAC')']'$loopend()$loopend()$loopend()**

 

Example output:

 

```
List created 2014-09-26 11:57:04

2014-08-05 [Rock] Genesis / Foxtrot (1972) [MPEG 1 Layer III]
2014-06-29 [Hardrock] Tzunami / Reanimation (2005) [MPEG 1 Layer III]
2014-04-30 [Soundtrack] Nine Inch Nails / ''The Perfect Drug'' (1997-06-09) [MPEG 1 Layer III]
2014-03-04 [Other] Gordon Goodwins Big Phat Band / (2009-03-20) [MPEG 1 Layer III]
2014-03-04 [Electronica] Tipper / Surrounded (2003) [MPEG 1 Layer III]
2014-01-19 [Soul, Jazz, Easy Listening] Sade / The Best of Sade (1994) [MPEG 1 Layer III]
2014-01-12 [Rock] Fehlfarben / 26 1/2 (2006-02-26) [MPEG 1 Layer III]
2014-01-11 [Rock] Aerosmith / Big Ones (1994) [MPEG 1 Layer III]
2014-01-11 [Rock] Aerosmith / Greatest Hits (1980-10-01) [MPEG 1 Layer III]
2013-12-23 [Rock] Alannah Myles / Black Velvet (2007-09-28) [MPEG 1 Layer III]
2013-11-22 [Rock] Michael Fehst, Gerd Klein / The Orange Cover (2008-07-14) [MPEG 2 Layer III]

```

 

DD.20140926.1232.CEST

---

<div class="post-metadata">

### Author: ![vkostas](https://community.mp3tag.de/user_avatar/community.mp3tag.de/vkostas/32/227_2.png) [@vkostas](https://community.mp3tag.de/u/vkostas)
#### Post date: [September 26, 2014, 10:03am UTC](https://community.mp3tag.de/t/turn-d-m-yyyy-into-yyyy-mm-dd/9074/11 "2014-09-26T10:03:47Z")

</div>

> [@DetlevD](#):
>
> Here is a shorter script with the same purpose, ...  
> sort by Date modified reverse, Albumartist or Artist, Album.
> 
> $loop($sub(4000000,$div(%\_file\_mod\_datetime\_raw%,86400)))

Yes. It is the raw datetime converted to days (60sec/min_60min/h_24h=86400sec) that makes the difference.  
Well done DetLev.
