Ferdi Derksen Posted November 6, 2015 Posted November 6, 2015 Hi folks, First of all - I'm not sure this is a explainable result - when so please explain (working with PW for only a few weeks now) My website has a lot of events with a start- and enddate. I'm looking for a complete selector which will return the events happening between today (2015-11-06) and a week from now (2015-11-13). I'm searching trough a lot of pages which have the following dates (testcase) ; Title | Startdate | Enddate --------------------------------------------- Event A | 2015-09-21 | 2015-09-22 Event B | 2015-09-21 | 2015-11-10 Event C | 2015-09-21 | 2015-11-30 Event D | 2015-11-07 | 2015-11-08 Event E | 2015-11-07 | 2015-11-19 Event F | 2015-11-18 | 2015-11-19 My expectations are events A and F not to show as a result (they have ended before today or starting after a week from now). Given the dates my selectortest is the following; template=event,enddate>=2015-11-06,enddate<=2015-11-13|startdate<=2015-11-13 ... which results in only Event B and D Simply switching the startdate and enddate did the trick; template=event,enddate>=2015-11-06,startdate<=2015-11-13|enddate<=2015-11-13 ... which results in events B, C, D and E My question, why??
ryan Posted November 6, 2015 Posted November 6, 2015 You can use "|" to OR fields, or OR values, but not expressions. Your selector is translating to something you didn't intend. I think the selector you might be attempting is instead this: template=event, enddate>=2015-11-06, enddate|startdate<=2015-11-13 Or you could use OR-groups: template=event, enddate>=2015-11-06, (enddate<=2015-11-13), (startdate<=2015-11-13) Either of the above selectors says: The template must be event. AND The enddate must be greater than or equal to 2015-11-05. AND (The enddate must be less than or equal to 2015-11-13 OR the start date must less than or equal to 2015-11-13). 5
diogo Posted November 6, 2015 Posted November 6, 2015 enddate<=2015-11-13|startdate<=2015-11-13 the OR operator "|" evaluates the first part and follows to the second only if the first is false. In this case the start day is never evaluated because it cannot possibly be true if the first is false. The start has to be earlier then the end. PS: True, I didn't even think that you are using OR between expression. Ryan to the rescue already 3
Ferdi Derksen Posted November 6, 2015 Author Posted November 6, 2015 That's the way I like it, even less code needed Those explanations are completely understandable! Thank you - both Ryan and Diogo for the fast replies.
LostKobrakai Posted November 6, 2015 Posted November 6, 2015 While ryan's code does certainly work you should be aware that this code wouldn't find events, that are longer than the mentioned "5 days from now" but still currently active. Such events could start before today and end after more than 5 days. To catch those as well you'd need another OR option like you can see in this topic: https://processwire.com/talk/topic/10682-help-with-date-range-selector/ 4
Ferdi Derksen Posted November 9, 2015 Author Posted November 9, 2015 While ryan's code does certainly work you should be aware that this code wouldn't find events, that are longer than the mentioned "5 days from now" but still currently active. Such events could start before today and end after more than 5 days. To catch those as well you'd need another OR option like you can see in this topic: https://processwire.com/talk/topic/10682-help-with-date-range-selector/ Please correct me if I'm wrong, but isn't this the same as Event C ? This event is also shown in the results. FYI; the selectors from the other topic also show the same results (B,C,D and E).
LostKobrakai Posted November 9, 2015 Posted November 9, 2015 Oh, you're right, I missread the selector of Ryan, which also seems to be way more elegant than mine.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now