Add 1 Hour manually to &tvFilters parameters

I’m using the following standard getDate snippet for multiple purposes.

<?php
return date('Y-m-d H:i:s');

The following &tvFilters work fine inside a getResources call.

&tvFilters= `eventStart>>[[!getDate]],eventStart!==`

However, the events can last up to 1 hour. This means that I need to filter them out 1 hour after the eventStart value. In other words, if the event start at 1pm in reality it should be filtered out after 2pm, because at 1:30pm (for example) the event still happening and should still be listed.

Challenge:
I know I can achieve this with a snippet but; is there a solution to this problem without creating or modifying existing TVs or snippets? Is it possible to add 1 hour within the getResources call?

Thank you in all in advance for you help

As your snippet already returns a formatted string of the time, it would be very impractical to try to achieve this.

My suggestion: Add an optional parameter/property to your getDate snippet. So when you call it without the property it works as before, and when you add an offset-property [[!getDate? &offset=`+1 hour`]] it takes that into account.

Like in this extra:

By the way, this is the solution to your challenge:

[[!getResources?
    ...
	&where=`["EXISTS (SELECT 1 FROM `modx_site_tmplvars` t INNER JOIN `modx_site_tmplvar_contentvalues` tc ON tc.tmplvarid = t.id WHERE CAST(tc.value AS DATETIME) > DATE_SUB(NOW(), INTERVAL 1 HOUR) AND t.name = 'eventStart' AND tc.contentid = `modResource`.id)"]`
]]

Really intuitive, isn’t it? :wink:

1 Like