Search

I’m just building my first system with Symphony, and I was wondering how I would go about filtering the articles between two dates. I have a “From date” and “To date” field, how would I filter the data source between these two fields? I’m having a bit of trouble understanding the syntax. :)

What do you mean by

I have a “From date” and “To date” field

Fields in a section or inputs in a form?

For two URL-parameters you can use {$start} to {$end} where both $start and $end-parameters are in the form of YYY-MM-DD. If they’re POST- or GET-values, you might have to use the Global Param Loader extension.

Whoops, sorry! I meant to specify that they’re section fields. I want the data source to only show data between pre-specified dates, there will be no input from the frontend.

Since you can’t have two output-parameters in one single datasource (discussion about that issue) you’ll have to create two datasources. One is returning your startdate $ds-start, the other one is returning your enddate $ds-end. You can then use both for your third article-datasource like {$ds-start} to {$ds-end}.

Param-names may vary, depending on your DS’ names.

I’m not quite sure I understand! I was attempting to do it with the filter results option, is there no way to choose “from-date” as a filter and have its value as “greater than {$this}” and a “to-date” with “less than {$this}”?

Now I am confused too. I thought you had two sections: One with articles, the second one with date-ranges (two fields per entry: one startdate, one enddate).

Now you want to select articles from a certain range, to be determined by a param from the frontend.

param = 20 (System ID of a range-entry in section 1)
=> section 1 returns: startdate = 2009-07-01, enddate = 2009-07-31
=> section 2 returns: articles from that range

Right?

I’m so confused! (as I imagine you are too!)

Here’s my section: http://skitch.com/throlkim/b2jmg/symphony-jobs

When I create the datasource, I want to limit its results to between those two fields at the end there.

Okay, the other way round then.

Do you want to filter by “Every entry for wich {$date-param} lies between ‘From date’ and ‘To date’”?

That can be done by two separate filter-conditions in your articles-datasource: Date from: later than {$date-param} and Date to: earlier than {$date-param}

And what exactly do you get from the frontend?

Yes, that’s the filter I’m trying to make! :)

Hmm, it doesn’t appear to be returning anything at the moment. Did I create the filter correctly? http://skitch.com/throlkim/b2jcw/symphony-data-sources-jobs

Is {$date-param} set? I still don’t understand how you’re setting your param.

Oh and its the wrong way round: From date is earlier than and To date is later than (otherwise {$date-param} had to be outside the range, on both sides simultaneously)

The question here is where are your start and end dates (that need to go into the filter) going to be coming from? Do you mean you want to filter where the current date is within that range, i.e. the entry is “current”?

If so, you won’t need output parameters to do this. Do it like this:

From date
earlier than {$now}

To date
later than {$now}

To see the date parameters available to you append ?debug=params to any frontend page and you’ll find things such as today, now, current-time etc.

@phoque — I didn’t know you could use the “earlier than” syntax. Are you sure this works?

This should find records where the from date is in the past and the end date is in the future.

Is that close?

nickdunn: They were introduced by Alistair and are mentioned in the docs:

Range filters such as, 2009-01-21 to {$today} would return an entry or entries whose field (typically a date field) matches dates since 2009-01-21, or ealier than {$today} and later than 2009-01-21

I hope they actually made it into 2.0.4 :-)

I’m still insanely confused. This is what I want to do:

  1. User inputs a start and end time when adding a job
  2. The data source selects data where the current date is between the start and end time

So jobs won’t show until the start date is reached, and expire when the end date passes.

EDIT: Just re-read nick’s solution, going to give it a quick go as I didn’t get it to begin with!

Awesome, that seems to have worked! Final solution was nick’s with {$today}. Thanks very much for the help guys, and sorry for making such a mess of explaining what I was intending to do!

Do you need entries to display for today as well? In the example above they will exclude entries finishing/starting today. Is there a “less than or equal to”?

Good point. I can make do without it for the time being, but hopefully someone has some more insight into it!

You can use earlier than and later than in a DS filter.

Is there a way of doing earlier than or equal to so you also include the compared date?

I found the code:

/symphony/lib/toolkit/fields/field.date.php

elseif(preg_match('/^(earlier|later) than (.*)$/i', $string, $match)){

    $string = $match[2];

    if(!self::__isValidDateString($string)) return self::ERROR; 

    $time = strtotime($string);

    switch($match[1]){
        case 'later': $string = DateTimeObj::get('Y-m-d H:i:s', $time+1) . ' to 2038-01-01'; break;
        case 'earlier': $string = '1970-01-03 to ' . DateTimeObj::get('Y-m-d H:i:s', $time-1); break;
    }

}

Now we just need a sensible word-like syntax.

  • earlier than or equal to is rather verbose
  • on or earlier than?

I was thinking about earlier than or {$date} but that might be too short :-)

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details