Is there an easy way to do this using titleformatting or has anyone a script that does this?
Edit: I'm only interested in the time gap expressed in the amount of days between first and last played.
If I didn't make any mistake (which is not very likely :D ), the following formula should return the number of days from the year 0 to the day expressed by the "date" variable:
$puts(date,%first_played%)
$puts(day,$day_of_month($get(date)))
$puts(month,$month($get(date)))
$puts(year,$year($get(date)))
$puts(years,$sub($get(year),1))
$puts(leap,$ifgreater($get(month),2,$ifequal($mod($get(year),4),0,$ifequal($mod($get(year),100),0,$ifequal($mod($get(year),400),0,1,0),1),0),0))
$add($get(leap),$select($get(month),0,31,59,90,120,151,181,212,243,273,304,334),$get(day),$mul(365,$get(years)),$sub($div($get(years),4),$sub($div($get(years),100),$div($get(years),400))))
In the example above, the "date" variable is assigned the %first_played% value, just change that first line of code to calculate the equivalent value for %last_played% and than calculate the difference.
Thanks for that davidleo, I had a go at it myself in the mean time but in a way more roudabout way compared to yours.
//Take into account leap year
$puts(FP.feb,$ifgreater($mod($year(%first_played%),4),0,28,29))
$puts(LP.feb,$ifgreater($mod($year(%last_played%),4),0,28,29))
//days for months FP
$puts(FP.monthdays_total,
$ifequal($right($month(%first_played%),2),01,31,
$ifequal($right($month(%first_played%),2),02,$get(FP.feb),
$ifequal($right($month(%first_played%),2),03,31,
$ifequal($right($month(%first_played%),2),04,30,
$ifequal($right($month(%first_played%),2),05,31,
$ifequal($right($month(%first_played%),2),06,30,
$ifequal($right($month(%first_played%),2),07,31,
$ifequal($right($month(%first_played%),2),08,31,
$ifequal($right($month(%first_played%),2),09,30,
$ifequal($right($month(%first_played%),2),10,31,
$ifequal($right($month(%first_played%),2),11,30,
$ifequal($right($month(%first_played%),2),12,31,
))))))))))))
)
//days for months LP
$puts(LP.monthdays_total,
$ifequal($right($month(%first_played%),2),01,31,
$ifequal($right($month(%first_played%),2),02,$get(LP.feb),
$ifequal($right($month(%first_played%),2),03,31,
$ifequal($right($month(%first_played%),2),04,30,
$ifequal($right($month(%first_played%),2),05,31,
$ifequal($right($month(%first_played%),2),06,30,
$ifequal($right($month(%first_played%),2),07,31,
$ifequal($right($month(%first_played%),2),08,31,
$ifequal($right($month(%first_played%),2),09,30,
$ifequal($right($month(%first_played%),2),10,31,
$ifequal($right($month(%first_played%),2),11,30,
$ifequal($right($month(%first_played%),2),12,31,
))))))))))))
)
//Days for months count
$puts(jan.count,31)
$puts(feb.count,$add($get(jan.count),28))
$puts(march.count,$add($get(feb.count),31))
$puts(april.count,$add($get(march.count),30))
$puts(may.count,$add($get(april.count),31))
$puts(june.count,$add($get(may.count),30))
$puts(july.count,$add($get(june.count),31))
$puts(aug.count,$add($get(july.count),31))
$puts(sept.count,$add($get(aug.count),30))
$puts(oct.count,$add($get(sept.count),31))
$puts(nov.count,$add($get(oct.count),30))
$puts(dec.count,$add($get(nov.count),31))
//first played
$puts(FP.monthdays,
$ifequal($right($month(%first_played%),2),01,$get(jan.count),
$ifequal($right($month(%first_played%),2),02,$get(feb.count),
$ifequal($right($month(%first_played%),2),03,$get(march.count),
$ifequal($right($month(%first_played%),2),04,$get(april.count),
$ifequal($right($month(%first_played%),2),05,$get(may.count),
$ifequal($right($month(%first_played%),2),06,$get(june.count),
$ifequal($right($month(%first_played%),2),07,$get(july.count),
$ifequal($right($month(%first_played%),2),08,$get(aug.count),
$ifequal($right($month(%first_played%),2),09,$get(sept.count),
$ifequal($right($month(%first_played%),2),10,$get(oct.count),
$ifequal($right($month(%first_played%),2),11,$get(nov.count),
$ifequal($right($month(%first_played%),2),12,$get(dec.count),
))))))))))))
)
//Last played
$puts(LP.monthdays,
$ifequal($right($month(%last_played%),2),01,$get(jan.count),
$ifequal($right($month(%last_played%),2),02,$get(feb.count),
$ifequal($right($month(%last_played%),2),03,$get(march.count),
$ifequal($right($month(%last_played%),2),04,$get(april.count),
$ifequal($right($month(%last_played%),2),05,$get(may.count),
$ifequal($right($month(%last_played%),2),06,$get(june.count),
$ifequal($right($month(%last_played%),2),07,$get(july.count),
$ifequal($right($month(%last_played%),2),08,$get(aug.count),
$ifequal($right($month(%last_played%),2),09,$get(sept.count),
$ifequal($right($month(%last_played%),2),10,$get(oct.count),
$ifequal($right($month(%last_played%),2),11,$get(nov.count),
$ifequal($right($month(%last_played%),2),12,$get(dec.count),
))))))))))))
)
//Calculate FP
$puts(year_FP.calc,$mul($year(%first_played%),365))
$puts(month_FP.calc,$sub(365,$get(FP.monthdays)))
$puts(day_FP.calc,$sub($get(FP.monthdays_total),$day_of_month(%first_played%)))
//Calculate LP
$puts(year_LP.calc,$mul($year(%last_played%),365))
$puts(month_LP.calc,$sub(365,$get(LP.monthdays)))
$puts(day_LP.calc,$sub($get(LP.monthdays_total),$day_of_month(%last_played%)))
$puts(FP_result,$sub($get(year_FP.calc),$add($get(month_FP.calc),$get(day_FP.calc))))
$puts(LP_result,$sub($get(year_LP.calc),$add($get(month_LP.calc),$get(day_LP.calc))))
//Subtract results
$puts(result,$sub($get(LP_result),$get(FP_result)))
You didn't make a mistake, our results are similar (it seems yours includes end date as well). But it seems you have the same problem as I encountered namely the leap years in between very long date gaps. Leap years are taken into account when the leap year is detected (using $mod, but I didn't bother with the 100 and 400 divider) on the first_played and last_played date but not in between the dates as far as I noticed. But it's close enough. Gonna dump my script and be using yours.
Btw, this (https://www.timeanddate.com) site is handy to verify results.
Yes, double checked on installed components, foo dynfil 1 beta 4. %first_played% and %last_played% are file written tags btw if that makes a difference.
Perhaps I'll look into it but I already got my working solution either from my own or from davidleo so there's not much incentive for me to look into it any further, but still appreciated for offering another way.
From reading the instructions it mentions foo_playcount.dll. I don't use that component, so I'm guessing that's the reason it yields unknown function.
Since I already have a working solution I don't want to install two separate components for something I already got working good enough....still that DAR rating thing looks interesting.
Not sure. If you have fields %first_played% and %last_played% I would assume it would work. foo_dynfil doesn't require foo_playcount.dll per say AFAIK. But DAR certainly does. Anyway, as you say it's all moot if you have a solution you're happy with.
C.
Just to be sure, are you trying to use $date_diff() as if it was any other titleformatting function, to be used all over foobar (in your playlist viewer/library viewer etc)?
Because the way foo_dynfil works is that you have to go to its settings, set up a custom field and use $date_diff() there to dictate what gets written to the field. Then you can refer to the field itself (e.g. %_my_date_difference%) to retrieve the computed value. So $date_diff() on its own can't be used anywhere else the way you were probably trying to use it.