The field formatter of the date field already allows to filter multiple values by a date range, if the field cardinality allows more than one value.
However currently it seems that the format for handling those range configurations is a bit special.
The filter values are processed by date_sql_handler::arg_replace() which provides its "very own syntax" to create a date based on the ISO 8601 notation.
I actually don't know why it does this, instead using the relative date formats provided by php.
Especially since there's no db query involved in date_prepare_entity().
But this just a side-note :)
The current notation is limited related to the usage of relative dates. It supports the usage of now which is handy but there's nothing like e.g. today.
In my concrete scenario I've to show the whole day all the dates of from today midnight (00:00:00) to tomorrow midnight.
Unfortunately with the current notation I need to know how many hours/minutes/seconds are past since 00:00:00 of today.
Here it would be great to have support for php's relative date formats.

Proposed resolution

For now I've created a patch which allows you to select which notation has to be used. Even if I'm quite sure that the usage of date_sql_handler::arg_replace() could be fully replaced in this particular case.
By default the new code uses to current notation, that way it's fully backward compatible.

Remaining tasks

User interface changes

The current patch introduces new radio elements in the field output formatter in the case it has a cardinality > 1.

API changes


date-allow-relative-dates-for-output-filter.patch4.25 KBdas-peter
PASSED: [[SimpleTest]]: [MySQL] 5,238 pass(es).
[ View ]


white_pawn’s picture

A big +1 from me.

SchwebDesign’s picture

This worked for us! THANK YOU! What a life saver this was in certain contexts.

This also solves this issue in the queue:

cmriley’s picture

Thank you ever so much as this works beautifully. Can we please get this officially committed soon please?

cmriley’s picture

Possibly I spoke too soon and or I am forgetting something. When I go into a repeating event it shows only the one date as intended however the date that it shows is for the next event not for that specific events date.

For example I have a repeating event the third Friday of each month. So my dates should be:

Friday, February 15, 2013
Friday, March 16, 2012
Friday, April 20, 2012

And so on. What I want to do is to show a event list with a view but instead of showing the next coming up event show the rrule date that is associated with that entry if that makes sense.

Is there any way to do that?

Thanks in advance

podarok’s picture

Issue summary:View changes
Status:Needs review» Needs work
Issue tags:+Needs tests

all feature requests should be covered by tests

podarok’s picture

Status:Needs work» Needs review
toelli’s picture

Iv been using this patch and we're having some wierd problems with timezone.

(line 502 date.module)

[0] = new DateObject($from, date_default_timezone());
$range[1] = new DateObject($to, date_default_timezone());

When you create the relative notation dates they get created in local time... and this is kinda bad if your local timezone is not UTC because below in the loop where we remove the multiple values it gets compared to the default UTC database timestamps...

I tried to change to "new DateObject($from, 'UTC');" but DateObject does not even seem to work with adding a timezone?

My solution:

[0] = new DateObject($from);
$range[0]->setTimezone(new DateTimeZone('UTC'));
$range[1] = new DateObject($to);
$range[1]->setTimezone(new DateTimeZone('UTC'));
vijaycs85’s picture

Issue tags:+sprint
bkosborne’s picture

And what about caching? Once you use relative dates, like dates that include the current date, it will only work if caching is disabled for that node view or if the page cache entry is cleared very often.

jwilson3’s picture

cache-busting is always hard to get right, but #9 sounds like a configuration issue. You must set your cache lifetime to something at or lower than your desired relative date granularity accuracy.

hwasem’s picture

Thanks, SchwebDesign, for the reference over here. This is EXACTLY what I was looking for. I applied the patch in OP and selected the relative date format. Now "today" and "now-12 hours" are working. Exactly what I needed to fix an issue I erroneously posted in Display Suite #2257435: Use a relative "Starting from" value in repeating date fields.

I sure hope this gets approved for Date as the partial implementation is confusing.