Search

I know this is a bit of a strange question, but I promise I have a good use case. I want to use a datasource to filter on the month value of a date field, but not the year or the day. What might be syntax look like for this? I thought that

{$year}-{$month}-{$day}

would work fine, even when $year or $day don't have values... but that doesn't seem to be the case. Any other ideas? Thanks for your help.

It's not currently supported unfortunately, a single value will be treated as the year. It's definitely possible though as months are generally 1-2 digits, not 4 (although having said this that would not be true for years 1-12).

I imagine being able to filter by month is a much more common scenario that filtering by the year 1-12.

Could you open an issue?

Seems that the Date field supports regular expression filtering. Might something like this work?

regex:^[0-9]{4}-{$month}-

Hopefully this would resolve to a regex such as this for January:

regex:^[0-9]{4}-01-

Which would hopefully find entries where the date starts with (^) four numbers ([0-9]{4}) followed by a hyphen and your month, followed by another hyphen.

I say hopefully because I haven't tried it...

I'm not sure how the filter deals with the curly braces for the regex quantifiers. If that doesn't work you can try something like

regexp:^(1|2)[0-9][0-9][0-9]-{$this-month}-

or not as strict

regexp:^[0-9]*-{$this-month}-

See http://getsymphony.com/discuss/thread/88304/1/#position-3 and http://getsymphony.com/discuss/thread/77/2/#position-40

Thanks so much guys, this worked perfectly! I was even able to get the month variable to not be required by using an asterisk.

regexp:^[0-9]*-{$url-month:*}-

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