1

When working with custom date fields, are there any solutions for searching dates? e.g. channel:entries search:datefield=""

The only thing that seems to work, if you search for the litteral unix timestamp e.g. 1394967600

Edit/clarfication
I'm searching for a way to use > and < for custom date ranges based on custom fields. The start_on and stop_before parameters only work on the entry_date.

Answer compilation:
- Query module (however, you won't be able to use other channel:entries parameters)
- SolSpace Date Field Filter (ads parameters to channel:entries tag)
- Low-Search (allows ranges on custom fields)

2 Answers 2

3

With entry_date you can use a start_on and stop_before parameter in your channel loop but cannot do an equivalent for custom date fields.

You have two good options here. The first is to use the {exp:query} module in place of a channel entry loop, and the other is to use a third-party search module such as Low Search

If you opt for the query method you should start a loop such as the following...

<ul>
    {exp:query sql="SELECT * FROM exp_channel_data JOIN exp_channel_titles 
 ON exp_channel_titles.entry_id = exp_channel_data.entry_id WHERE (exp_channel_data.channel_id = '7') AND (field_id_48 > '1194712120' AND field_id_48 < '1694712120')"}
        <li>{title} - {field_id_48}</li>

        {if no_results}
          <li>No results :-(</li>
        {/if}
    {/exp:query}
</ul>

Where '7' is your channel ID and field_id_48 is the ID of your date field.

You can also change the second reference to field_id_48 to a date field for "end date".

Change 1194712120 and 1694712120 to the correct UNIX time stamp for your date range.

The query module is free and built into ExpressionEngine, but you may need to enable it via the "Add-Ons > Module" screen in the control panel. Low Search is a paid for third-party add-on.

1
  • The query module is an option, but then you lose all functionality of the channel:entries module tag (you don't want to build your own category subqueries yourself in there). Low-search is currently the best option i think, but not free. Also i found Solspace Date-filter, which extends the channel:entries tag.
    – GDmac
    Commented Mar 16, 2014 at 12:30
2

GDmac

I think you can workaround this problem using a simple php code like

$timestamp = $this->EE->localize->string_to_timestamp("May 20th, 2007");

this will give you a timestamp value for your date which can by passed to {channel:entries} loop via embed variable.

or you can put it in a simple plugin if you don't want to use php.

you can use my plugin https://github.com/ahmad-saad/str_to_time

I hope this will help you

Regard's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.