($puts(char1,-)$puts(char2,-)$puts(tag,%date%)$puts(spacer1,$strchr($get(tag),$get(char1)))$puts(spacer2,$strrchr($get(tag),$get(char2)))$trim($substr($get(tag),$add($get(spacer1),1),$sub($get(spacer2),1)))
However, since this is isolating the month from a date formatted yyyy-mm-dd, it returns a numerical value.
No need for any of that. Just use $month(%date%) - (see "time and date functions")
I thought I would write a very long if statement to replace "01" with "January" & "02" with "February" & so on.
And for this you can use $select - this function takes a number, in this case $month, and returns the corresponding value from the string you specify -
$select($month(%date%),January,February,March,April,May,June,July,August,September,October,November,December)
^ So if the $month number is 7, it returns "July". Then combine that with the other date functions -
[$day_of_month(%date%) $select($month(%date%),January,February,March,April,May,June,July,August,September,October,November,December) $year(%date%)]
^ And it returns a date in the form of "25 July 2024".
However, the if statement does not work, it appears to always evaluate the above code as true no matter what value I specify. For example, the below is resulting in all the music sorting to January and none to February.
$if(($puts(char1,-)$puts(char2,-)$puts(tag,%date%)$puts(spacer1,$strchr($get(tag),$get(char1)))$puts(spacer2,$strrchr($get(tag),$get(char2)))$trim($substr($get(tag),$add($get(spacer1),1),$sub($get(spacer2),1))))=01, January, February)
Not the right syntax. Ignoring all that mish-mash for the moment, $if does not use symbols (=,> etc) for determining if something is equal or any other comparisons, rather it uses other functions. Use $if together with string compare functions like $strstr (partial match) or $strcmp (exact match) or $stricmp (exact match, only not case sensitive). There are also other forms such as $ifequal and $ifgreater that compare numbers.
The string compare stuff returns a true/false, so it goes immediately after $if in the condition part - "$if (condition is true?, then return this, else return that)". So for a quick example -
$if($strcmp(%album artist%,Various),true,false)
$if($strstr(%album artist%,Various),true,false)
^ If the %album artist% tag in this case had exactly the letters "Various Artists" (without quotes) and nothing else, the $strcmp would return false (not an exact match), and the $strstr would return true (partial match).
$ifequal($month(%date%),7,true,false)
^ If the month equals 7, the true part is returned, otherwise false.
On a similar note I was messing around with some other if statement sorting patterns in the form of:
$if(<field> MISSING, sort this way, sort that way)
You cannot mix "query syntax" (used for library searches) in with "title formatting" (used to display and format tags) - they are two different languages. (Though you can the other way around, use title formatting in query syntax)
Having said that, I think title formatting will usually ignore any extraneous words in the condition part. The field itself returns a true/false if it is tagged or not, so just use -
$if(%field%,true,false)
Although whether it works for sorting might depend where exactly you are entering it, and Library Tree (being a javascript that has to parse things over and over) might not support every type of usage.
If you're on 32-bit foobar and want to learn title formatting by seeing exactly what each part of a script is evaluating to, I suggest install Title Formatting Sandbox. Select a track in playlist with tags you want to test, open it in View menu > Title Formatting Sandbox, and enter or paste any scripts there, and you can click on each part of the script to see what it returns from the selected track. Using this you can end up writing some complex stuff and see exactly what is happening at each step.