1 users online. Create an account or sign in to join them.Users
Data Source: Filter Articles by Date
This is an open discussion with 44 replies, filed under General.
Search
There's a $today param which represents the current date, and you can additionally filter by date ranges in date fields, so something like {$year}-{$month}-{$day} to {$today} should work.
Ah, that's working great! A second question though: I know use 2008-01-01 to {$today} to get all articles between the 1st for January up to today. Is there a way to specify a condition that all articles before today are shown (independent of a starting date)?
By the way: Is this a custom Symphony syntax or is it connected to a "language" (PHP, XSLT ...)?
Scott, does this indicate that it's possible to use logical operators in the filters as well?
@Skybidu: if you want all articles until today, simply set your starting date very early:
1950-01-01 to {$today}
This is custom syntax. It is also possible to break the dates down:
{$this-year}-{$this-month}-01
The above will always result in the first of this current month and year.
The curly brace is a global rule in the DS filter to identify something as, "please parse the containing string". The to keyword is used specifically for date filtering.
Thanks, Allen!
@thoresson: Partially. The only allowed operators are:
Enumerators -- {$year:2004} -- If $year is not set, the value is then 2004.
Union -- yellow, blue -- get me entries that are either yellow or blue.
Intersection -- yellow + blue -- get me entries that are yellow and blue.
range -- 2007-01-01 to 2008-01-01 -- from an earlier date to a later date.
range (shortcut) -- 2007-01 -- this is essentially the equivalent of 2007-01-01 to 2007-01-31. Or in another words, "get me all entries in January".
MySQL regex -- regexp:expression -- this allows MySQL's built-in regex matching functionality.
if you want all articles until today, simply set your starting date very early
Just as a note for everyone else: This seems not to work with dates before 1902. I don't know why and it's certainly not that important.
Allen, would it be possible to add a logical NOT? I've got a situation where I want to exclude all entries of a specific category.
@Thoresson: Unfortunately that is not possible. This is a technical limitation. Normally, when you filter by a value, it is considered a direct reference, i.e. "pick all entries with the value 'cat'". On the other hand, not value is the equivalent to saying, "get every value in the system, now filter out the ones I don't want".
However, what we've found so far is that there are creative ways to solve a problem that revolves around negation logic.
Ok. But this is probably easily solved in XSLT.
What's "negation logic"?
Negation Logic => Not Logic
Maybe have a constant for the beginning of time and the end of time:
{BIG_BANG} to {$today}
{$today} to {ETERNITY}
I've also noticed, like Nils, that 2100-01-01 did not work for the date logic.
Is there a way I can increment today's value? Say I'm filtering from $today to the end of time. I'd like to make it an exclusive filtering by changing only the days after today.
ie.
{$this-year}-{$this-month}-{$this-day++} to 2010-01-01
I'm basically making an expired DS. If I use {$today} to 2010-01-01 and 1910-01-01 to {$today} (on a different DS) I'd have the same data for items that expire today.
I'm basically making an expired DS. If I use {$today} to 2010-01-01 and 1910-01-01 to {$today} (on a > different DS) I'd have the same data for items that expire today.
Has anyone figured out how to setup an "expired" DS? I'm trying to set up an upcoming events list where the events remove when they hit their expiration date. Can anyone give me pointers in how to accomplish this in the s2 (beta 5) data source editor?
bzerangue:
As others have suggested, in the data source, I filter by date with these terms: {$today} to 2010-01-01
That pulls all items from today onward -- even if it's past the time of the event (aka the event was coded at 8:00, but it's now 13:00)
My question is: is it possible to do an OR operator with field filtering? I have a field for start date, and another for end date -- so I would like to have a datasource that returns data that matches:
start: {$today} to 2010-01-01 OR end: {$today} to 2010-01-01
Matt, this can be done, but you'll need to use 2 data sources in combination, one with each filter rule separately. (Let's call these start-after and end-before.) Then you're XPath to select results might need to be something like /data/start-after/entry|/data/end-before/entry.
The general design behind DS filtering is that "and" is achieved by adding rules to a DS, while "or" is achieved by adding separate DSs.
Regarding the date range shortcuts, '2007' returns all entries from 2007, and '2007-01' returns all entries from January 2007, but '2007-01-01' returns no entries (though entries with that date exist). Should '2007-01-01' not also serve as a shortcut for '2007-01-01 to 2007-01-01'? I'm running 2.0.1 release.
Create an account or sign in to comment.
I'm trying to understand the logic how to filter the result of data sources.
Given a section with articles that include a publish date. Articles could be written in advance and should be shown on the live site when the publish date is lower than the current date or equals it.
How can I achieve this behaviour using the new Data Source editor? Thanks for your help!