Ensure Date always has full Year / Month / Day format

This might seem odd but I’d like to ensure the date is always in the full format of year/month/day even if the month or day is missing from the musicbrainz release I’m tagging against.

Lets take this release as an example, https://musicbrainz.org/release/5612dc7a-2dd0-4e38-a26d-e2f5b0467a6e. It has a date of “1980/06”. However, I’d like to tag this as “1980/06/01”. So, I’d like to assume that if the day is missing it becomes 01. Same for anything that has just a year. So, for example if the release was “1980” with both month and day missing it would become “1980/01/01”.

Is there some way I can script this ?

The brute force way is to check the length of the date string and pad accordingly. For example, assuming that you’re parsing the date stored in %date%:

$if($eq($len(%date%),4),$set(date,%date%-01))  $noop( Add missing month )
$if($eq($len(%date%),7),$set(date,%date%-01))  $noop( Add missing day )
3 Likes

Very clever and elegant. I have some more testing to do however I added the following code snippet to my scripting tagger and so far it appears to be working well.

$set(date,$if2(%originaldate%,%date%))
$if($eq($len(%date%),4),$set(date,$if2(%originaldate%-01,%date%)))  $noop( Add missing month )
$if($eq($len(%date%),7),$set(date,$if2(%originaldate%-01,%date%)))  $noop( Add missing day )

I thank you ever so much.

1 Like

After a bit more testing I needed to slightly adjust the syntax. Sometimes when month & day are missing it would only add the missing month but not the day.

$set(date,$if2(%originaldate%,%date%))
$if($eq($len(%date%),4),$set(date,$if2(%originaldate%-01-01,%date%))) $noop( Add missing month & day )
$if($eq($len(%date%),7),$set(date,$if2(%originaldate%-01,%date%))) $noop( Add missing day )

The above is working really. Again, thank you for your help.

1 Like