INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: "When in time?" searchlists  (Read 4500 times)

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9165
"When in time?" searchlists
« on: January 08, 2016, 12:58:48 am »

Over in the MAC forum, the question was asked...

If I wanted to create a string that would provide me a range of dates, i.e. this week, last week, this year, last year, how would I go about creating such a string?

The answer works equally as well on Windows MC, and might interest some of you who never venture in there....
The search strings required are listed below, and for those who want to cut out the work of building the view around them from scratch, attached to this post are a couple of "saved view" files that will load similar views for date imported data, and last played data.

The views are designed to go on the root of your MC tree. You could, if you liked, place one in each media type category in the tree, then customise the view, removing the then redundant "Media Type" pane, and placing a tick in the "Use parent scheme search rules" box.

The strings below are all based on "Date Imported". Replace with "Last Played" for playback stats.

Today
Code: [Select]
[=isequal(formatdate([Date Imported,0],dd//MM//yyyy),formatdate(now(),dd//MM//yyyy),8)]=1
Yesterday
Code: [Select]
[=isequal(formatdate([Date Imported,0],dd//MM//yyyy),formatdate(math(now()-1),dd//MM//yyyy),8)]=1
This Week
Code: [Select]
[=isequal(if(isequal(formatdate([Date Imported,0],%W),00),formatdate(math([Date Imported,0]-formatdate([Date Imported,0],dd)),yyyy%W),formatdate([Date Imported,0],yyyy%W)),if(isequal(formatdate(now(),%W),00),formatdate(math(now()-formatdate(now(),dd)),yyyy%W),formatdate(now(),yyyy%W)))]=1
Last Week
Code: [Select]
[=isequal(if(isequal(formatdate([date imported,0],%W),00),formatdate(math([date imported,0]-formatdate([date imported,0],dd)),yyyy%W),formatdate([date imported,0],yyyy%W)),ifelse(isequal(formatdate(now(),%W),00),math(formatdate(math(now()-formatdate(now(),dd)),yyyy%W)-1),isequal(math(formatdate(now(),%W)-1),0),formatdate(math(now()-formatdate(now(),dd)),yyyy%W),1,math(formatdate(now(),yyyy%W)-1)))]=1
This Month
Code: [Select]
[=isequal(formatdate([Date Imported,0],MM//yyyy),formatdate(now(),MM//yyyy),8)]=1
Last Month
Code: [Select]
[=isequal(formatdate([Date Imported,0],MM//yyyy),if(isequal(formatdate(now(),MM),01),12,padnumber(math(formatdate(now(),MM)-1),2))//if(isequal(formatdate(now(),MM),01),math(formatdate(now(),yyyy)-1),formatdate(now(),yyyy)),8)]=1
This Year
Code: [Select]
[=isequal(formatdate([Date Imported,0],yyyy),formatdate(now(),yyyy),8)]=1
Last Year
Code: [Select]
[=isequal(formatdate([Date Imported,0],yyyy),math(formatdate(now(),yyyy)-1),8)]=1
and as promised above, two saved views in the attached zip file.

Instructions
Download the attached zip file.
On Windows, extract the contents to: "C:\Users\[user name]\AppData\Roaming\J River\Media Center 21\Library\Saved Views"
If the saved views folder is not there, create it.

Once in place, go to MC, from the top menu choose "View > Add View > Add Library View" and use the view picker to add the views.

Enjoy.

-marko

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9165
Re: "When in time?" searchlists
« Reply #1 on: January 08, 2016, 01:23:54 pm »

I received this via PM, but will answer here for the benefit of all...

Quote from: Eight Dancing Monkeys
http://yabb.jriver.com/interact/index.php?topic=102478.0

does this work for last week?

[=isequal(formatdate([date imported,0],yyyy-%U), formatdate(math(now() - 7), yyyy-%U))]=1

The answer is "Yes". The output from that will be "year-week#", 2015-51, for example, with a "but" for this week and last week only...

First of all, about last week...
Some of us prefer our weeks to run from Sunday to Monday.
Some of us prefer our weeks to run from Monday to Sunday.
Some of us prefer our weeks to be 'the last seven days'

For eight dancing monkeys above, the preference is 'last seven days'.
For eight dancing monkeys above, the preference is for the week to start on a Sunday, which is translated in MC by using %U
My preference is that the week begins on a Monday, which in MC, is translated by using %W

The thing with week numbers and MC though, is that it splits last week (w/c 28th December 2015) into week 52 of 2015 and week zero of 2016. Which means that, up until Monday 11th January 2016, the string presented by eight dancing monkeys will only return tracks that match week zero, not the full seven days. Once we're past the 'new year / old year split, everything will work fine as expected.

All of the strings presented in my post above, as well as the attached views, assume the week begins on Monday, treat "last week" as being seven days from the previous Monday, and correctly deal with the whole "week zero" thing.

eight dancing monkeys,
Hope that helps...

-marko

milehigh

  • Regular Member
  • World Citizen
  • ***
  • Posts: 109
  • nothing more to say...
Re: "When in time?" searchlists
« Reply #2 on: January 08, 2016, 06:00:22 pm »

Thanks Marco - awesome views.  Much appreciated.  Is there a repository somewhere where these views are stored?  It would be nice to see what other people have come up with - as I know that they can be very powerful.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9165
Re: "When in time?" searchlists
« Reply #3 on: January 09, 2016, 02:11:14 am »

The sharing thing crops up every now and then, and while the theory is great, in practice, they just don't fly. We've tried in the past with smartlist sharing threads, expression ideas sharing threads and the like, and after a little initial interest and flurry of activity, the threads die off, ending up buried on page 52 of the forum, forgotten, abandoned, covered in cobwebs.

The main reason for this is, I believe, that a fair few of us have customised the life out of our MCs and barely remember what the defaults are. I often find myself doing a clean MC install on another machine just remind myself what the defaults are for something I'm trying to help with. Custom library fields, and a lot of the stuff that keeps us using MC, and thanking JRiver for selling us such a malliable product, means that a lot of what works for me won't work on other MCs.

Now and again, we can share something that makes a few people go "Wow", as they begin to realise just how flexible MC can be, and often come back with cool new ideas from their inspiration.

Take the "Play Stats" view I shared above. You've seen it right? That "Last Played Calendar" pane is an expression based pane. Here, I used that expression to create a library field which is then available for use in any view I want it. Had I shared the view that way, without replacing the field with the actual expression, it would not have worked for you, it would have been a blank pane.

Now you have it though, you can open it for editing and see how it was created and how it works, which can be invaluable when you're trying to learn what's possible, so there is value in sharing, but don't think those kind of "share your views here" threads are the answer. I think the best approach for everyone looking to learn is to just ask. You'll get help, ideas, explanations of the boundaries (because as vast as the playing field is, it does have boundaries), and maybe even a helpful jvi file to demonstrate a procedure :)

Glad you found the views useful. Remember you can tweak them to suit, and you don't have to worry about breaking them as you have originals saved in the view picker.

-marko

Cmely

  • Junior Woodchuck
  • **
  • Posts: 81
Re: "When in time?" searchlists
« Reply #4 on: January 07, 2017, 04:55:09 am »

I have a problem on my MC with this expression:

Code: [Select]
formatdate(math(now()-1),dd//MM//yyyy)
is not working for me and I don't know why ?
If I use this to create an expression column in a view, I get no result (empty field). If I use the following expression :

Code: [Select]
=formatdate(now())
I get the correct result. Do you have any idea why ?

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9165
Re: "When in time?" searchlists
« Reply #5 on: January 08, 2017, 01:29:35 am »

I'm not sure. I just copied "formatdate(math(now()-1),dd//MM//yyyy)" from your post above and pasted it into an expression column, and it gave me yesterday's date, as expected.

Any other clues to work on?
Is the date set correctly on your PC?

-marko

Cmely

  • Junior Woodchuck
  • **
  • Posts: 81
Re: "When in time?" searchlists
« Reply #6 on: January 08, 2017, 02:55:23 am »

I'm not sure. I just copied "formatdate(math(now()-1),dd//MM//yyyy)" from your post above and pasted it into an expression column, and it gave me yesterday's date, as expected.

Any other clues to work on?
Is the date set correctly on your PC?

-marko

Fridden gave the correct anwser on this post

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9165
Re: "When in time?" searchlists
« Reply #7 on: January 08, 2017, 03:31:04 am »

Yup, the clue...
Could it be a conflict between date format in MC (which is in english on my PC) and my system configuration (which is in french) ?

and the solution:
Check out the documentation for Math() at
http://wiki.jriver.com/index.php/Miscellaneous_Functions#Math

Special care must be taken with the Math() function and locales that use , (comma) as a decimal separator. Many Media Center fields and the return values from functions may contain comma as the decimal point. Your expressions will need to Replace() these before passing the values to Math(), which always uses dot . as the numeric decimal point.

You need to write the expression like this:
=FormatDate(math(replace(now(), /,, .) -1),dd//MM//yy)

Glad you got it figured.
Pages: [1]   Go Up