Author Topic: Worded Date Virtual tag  (Read 2133 times)

johnmillsjr

  • Full Member
  • ***
  • Posts: 145
Under useful tag formulas, there is a way to reformat releasesortorder (YYYYMMDD) to yyyy/mm/dd.

I'm wondering if anyone can help me make a worded date coversion:

ie. 19590821= August 21, 1959 (with or without comma)

Could one of you Virtual Tag experts could help me out here?

hiccup

  • Sr. Member
  • ****
  • Posts: 7893
Try this:

Code
$IsNull(<year>,,$Replace($Replace($Replace($Replace($Replace($Replace($Replace($Replace($Replace($Replace($Replace($Replace($If($Left($Pad(<year>,8)")",4)=0000,,$Right($Left(<year>,6),2)),01,"January "),02,"February "),03,"March "),04,"April "),05,"May "),06,"June "),07,"July "),08,"August "),09,"September "),10,"October "),11,"November "),12,"December ")$If($Left($Pad(<year>,8),2)=00,,$Right(<year>,2)", ")$Left(<year>,4))

updated,
It now also gives correct results when the source tag contains the year and month but not the day.
So it should now work when the source tag is formatted as:
yyyy
yyyymm
yyyymmdd
Last Edit: October 12, 2020, 06:33:18 PM by hiccup

johnmillsjr

  • Full Member
  • ***
  • Posts: 145
My sincerest and deepest gratitude for your help :)

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34363

hiccup

  • Sr. Member
  • ****
  • Posts: 7893
$Date(<Year>,"MMMM, yyyy") might work

That would probably work for the 'date added' tag, but not for a year or date tag that is formatted like 19991231 or just 1999.

(and a small correcting detail, the OP would require: $Date(<Year>,"MMMM d, yyyy")
Last Edit: October 11, 2020, 11:28:49 AM by hiccup

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2462
I'm wondering if anyone can help me make a worded date coversion:

ie. 19590821= August 21, 1959 (with or without comma)

A more concise solution is to first construct a version of your date that the Date function understands, like yyyy-mm-dd.

If you know the tag value will have 8 digits, you can use this:

Code
$Date($RxReplace(<CustomDate>,"([0-9]{4})([0-9]{2})([0-9]{2})","$1-$2-$3"), "MMMM d, yyyy")
This will also work if you only have the year in the same field. It will just display it as is.

If you need to cater for values that have only the year and month (i.e. yyyymm), add a $Len function to check the length first and add a dummy date value so the $Date function can still parse it.

Code
$If(
$Len(<CustomDate>)=6,
$Date($RxReplace(<CustomDate>,"([0-9]{4})([0-9]{2})","$1-$2-01"),MMMM, yyyy),
$Date($RxReplace(<CustomDate>,"([0-9]{4})([0-9]{2})([0-9]{2})","$1-$2-$3"),MMMM d, yyyy)
)
-edit-
Fixed incorrect placeholder tag in second formula.
Last Edit: October 12, 2020, 03:21:54 AM by Zak
Bee excellent to each other...

hiccup

  • Sr. Member
  • ****
  • Posts: 7893
A more concise solution is to first construct a version of your date that the Date function understands, like yyyy-mm-dd.

A very nice solution indeed.
It would be interesting to learn the exact workings and mechanics of the $Date function.
I searched, but couldn't find an explanation on what it does exactly, or what the conditions/prerequisites are for it to function.
E.g. I am guessing that regional Windows settings may play some role?
What does it need exactly to output something useful?

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2462
It would be interesting to learn the exact workings and mechanics of the $Date function.
I searched, but couldn't find an explanation on what it does exactly, or what the conditions/prerequisites are for it to function.
E.g. I am guessing that regional Windows settings may play some role?
What does it need exactly to output something useful?
I don't know how Steven has implemented functions in MusicBee, but would assume $Date uses something like the DateTime.Parse method.

https://docs.microsoft.com/en-us/dotnet/api/system.datetime.parse
Bee excellent to each other...

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34363
Thats right. Any field values successfully converted to a valid date will work with the $Date() function
The supported date formats are documented here:
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

johnmillsjr

  • Full Member
  • ***
  • Posts: 145

Try this:

Code
$IsNull(<year>,,$Replace($Replace($Replace($Replace($Replace($Replace($Replace($Replace($Replace($Replace($Replace($Replace($If($Left($Pad(<Year>,8)")",4)=0000,,$Left($Right(<Year>,4),2)),01,"January "),02,"February "),03,"March "),04,"April "),05,"May "),06,"June "),07,"July "),08,"August "),09,"September "),10,"October "),11,"November "),12,"December ")$If($Left($Pad(<year>,8)),4)=0000,,$Right(<Year>,2)", ")$Left(<Year>,4))

Wow I'm spoiled for choice!



One thing I didn't mention, something I discussed a few months ago is circa dates.

Is it possible to hide a part of the date if it's set to "00" for instances where I can't pin down the exact day or month and add a preceding "c."

ie

19681200 returns c. December, 1968
or
19550000=c. 1955

A simpler way may be to set up the worded date virtual tag to null if any YY, MM, DD ="00" and then write in the circa date on the end of the tag before it in my Virtual Tag Subheader

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2462
Is it possible to hide a part of the date if it's set to "00" for instances where I can't pin down the exact day or month and add a preceding "c."

ie

19681200 returns c. December, 1968
or
19550000=c. 1955

It's starting to get ugly, but this will do that:

Code
$If($IsMatch(<CustomDate>,"[0-9]{4}0{4}"),"c. "$Left(<CustomDate>,4),$If($IsMatch(<CustomDate>,"[0-9]{6}0{2}"),"c. "$Date($RxReplace(<CustomDate>,"([0-9]{4})([0-9]{2})0{2}","$1-$2-01"),MMMM, yyyy),$Date($RxReplace(<CustomDate>,"([0-9]{4})([0-9]{2})([0-9]{2})","$1-$2-$3"),MMMM d, yyyy)))

I'll also go on the record as saying that I don't think 'circa' is really the right word to use here.
I get what you're doing, but:

19681200 isn't circa December, 1968. It is in December, 1968.
19550000 isn't circa 1955. It is in 1955.

But as long as you know what it means, I guess it's copacetic.


A simpler way may be to set up the worded date virtual tag to null if any YY, MM, DD ="00" and then write in the circa date on the end of the tag before it in my Virtual Tag Subheader

You'll simplify everything if you meet MusicBee halfway and format your dates in a format that .Net can understand. All of these lengthy virtual tags are only necessary because you're formatting your dates in a way that doesn't mean anything to a computer.

I format my dates as either "yyyy", "yyyy-mm" or "yyyy-mm-dd" and this much simpler virtual tag does basically the same formatting you're asking for, because the $Date function already knows what to do with them:

Code
$If($Len(<CustomDate>)=4,<CustomDate>,$If($Len(<CustomDate>)=7,$Date(<CustomDate>,MMM yyyy),$Date(<CustomDate>,d MMM yyyy)))
Bee excellent to each other...

johnmillsjr

  • Full Member
  • ***
  • Posts: 145

It's starting to get ugly, but this will do that:

I'll also go on the record as saying that I don't think 'circa' is really the right word to use here.
I get what you're doing, but:

19681200 isn't circa December, 1968. It is in December, 1968.
19550000 isn't circa 1955. It is in 1955.

But as long as you know what it means, I guess it's copacetic.


A simpler way may be to set up the worded date virtual tag to null if any YY, MM, DD ="00" and then write in the circa date on the end of the tag before it in my Virtual Tag Subheader

You'll simplify everything if you meet MusicBee halfway and format your dates in a format that .Net can understand. All of these lengthy virtual tags are only necessary because you're formatting your dates in a way that doesn't mean anything to a computer.

I format my dates as either "yyyy", "yyyy-mm" or "yyyy-mm-dd" and this much simpler virtual tag does basically the same formatting you're asking for, because the $Date function already knows what to do with them:

Code
$If($Len(<CustomDate>)=4,<CustomDate>,$If($Len(<CustomDate>)=7,$Date(<CustomDate>,MMM yyyy),$Date(<CustomDate>,d MMM yyyy)))

Thank-you for your help. I have to use release sort format because Album Covers view forces you to sort tracks by %discnumber% and %track% - so i have to put YYYYMMDD into %discnumber% and the recording order into %track% to get this result:


Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2462
Interesting. It may actually be easier to post a wishlist request for the ability to apply custom track sorting to the Album Covers view.  ;)

(if you haven't already)
Bee excellent to each other...

hiccup

  • Sr. Member
  • ****
  • Posts: 7893
Note that I made a small improvement/update to my non-regex solution.
It now accepts yyyy, yyyymm and yyyymmdd