Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: date-based title formatting string help needed (Read 4588 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

date-based title formatting string help needed

Hi all,

[EDIT: Firstly, subtitle was supposed to read:
"shortest string to get no. of days" ]

I'm struggling to find a succinct method of getting the number of days from what, in the cwb_hooks days, would have been done by date_diff.
So if we have two date functions:

%added% and %last_played%

How do I get the number of days by subtracting one from the other in the shortest title formatting formula/script?

Many thanks for any suggestions/help.

C.
PC = TAK + LossyWAV  ::  Portable = Opus (130)

date-based title formatting string help needed

Reply #1
I've thought about doing this myself, but gave up once I considered how I should deal with leap years. It might be possible, but having to deal with years, months, then days (note that you can't just add 365 days when the two dates have different years) would likely make it too slow for mass use (i.e., to be displayed in a playlist column).

Edited to add: I should note that I was trying to do this without using $puts; if you can use $puts, you'll likely have an easier time with it.

date-based title formatting string help needed

Reply #2
I remember foosion saw this is a sign of madness 

Edit: Ah, I see from post #2 that the code relies on ColumnsUI. Probably just as well...
I'm on a horse.

date-based title formatting string help needed

Reply #3
Code: [Select]
 
all work and no play makes jack a dull boy
all work and no play makes jack a dull boy
all work and no play makes jack a dull boy
all work and no play makes jack a dull boy
all work and no play makes jack a dull boy

etc...

I see where foosion's coming from, but it's equally madness that it needs to be so damn convoluted.

cwb_hooks got deprecated partly AFAIK due to its system time. It would be good if someone could hack it and provide a stripped down version with some of its functions intact. cwb_datediff or whatever it was, was very useful.

That's a real shame that there's no simple way of determining the number of days between two of fb2k's date functions. That's a real killer for what I had in mind.

Thanks Synthetic Soul, I'll need to think on your script.

C.
PC = TAK + LossyWAV  ::  Portable = Opus (130)

 

date-based title formatting string help needed

Reply #4
I had played with this a while back and found/came up with something that does fairly well (+/- 1 day) as far as I have tested and accounts for leap days.


Code: [Select]
$puts(d1,2008-01-01)$puts(d2,2007-01-01)
$puts(dd1,
    $puts(date,$get(d1))
    $puts(y,$year($get(date)))
    $puts(m,$month($get(date)))
    $puts(d,$day_of_month($get(date)))
    $ifgreater(2,$get(m),$puts(m,$add($get(m),12))$puts(y,$sub($get(y),1)),)
    $div($add($mul($get(y),36500),$mul($get(y),25),$mul($get(y),-1),$div($get(y),4),$mul($get(d),100),$mul($add($mul($get(m),153),8),20)),100)
)
$puts(dd2,
    $puts(date,$get(d2))
    $puts(y,$year($get(date)))
    $puts(m,$month($get(date)))
    $puts(d,$day_of_month($get(date)))
    $ifgreater(2,$get(m),$puts(m,$add($get(m),12))$puts(y,$sub($get(y),1)),)
    $div($add($mul($get(y),36500),$mul($get(y),25),$mul($get(y),-1),$div($get(y),4),$mul($get(d),100),$mul($add($mul($get(m),153),8),20)),100)
)
$ifgreater($get(dd1),$get(dd2),$sub($get(dd1),$get(dd2)),$sub($get(dd2),$get(dd1)))


It adjusts each date as if the year started on March 1 (I forget why this is important) and then calculates the number of days that date represents using:
365*year + year/4 - year/100 + year/400 + days + (153*month+8)/5
It then calculates the difference and returns the absolute value.

It could be condensed a bit more if you really want to get it shorter.

date-based title formatting string help needed

Reply #5
Thanks Qwerty.
I'm happy to give or take a day over periods > month.
I'll give it a go.

Cheers,

C.
PC = TAK + LossyWAV  ::  Portable = Opus (130)

date-based title formatting string help needed

Reply #6
It adjusts each date as if the year started on March 1 (I forget why this is important)
Presumably something to do with leap years.

This doesn't solve the fact that you need some way of getting the current date.
I'm on a horse.

date-based title formatting string help needed

Reply #7
I think that can be done.
Have a look here.

By the way, any idea how easy it is to write a script that recursively changes the date modified time stamp of files in various directories?

I'm thinking foo_run with batch file / script.

C.
PC = TAK + LossyWAV  ::  Portable = Opus (130)

date-based title formatting string help needed

Reply #8
cwb_hooks got deprecated partly AFAIK due to its system time. It would be good if someone could hack it and provide a stripped down version with some of its functions intact. cwb_datediff or whatever it was, was very useful.

It got deprecated in first place because of it's functions, because it's simply impossible to provide any function with the latest SDK.