<p>Looks like I finally found an answer to it</p>

<p>year being my param</p>

<p>date being my custom date field</p>

<pre><code>{% set dateParam = 'and, &gt;= ' ~ year ~ '-01-01, &lt; ' ~ (year + 1) ~ '-01-01' %}
&lt;ul&gt;
    {% for entry in craft.entries.section('evenements').order('date desc').date(dateParam) %}
        &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;
</code></pre>

CC BY-SA 3.0
2016-03-09T22:33:21.647Z
Curiously, does that work? I would think you'd need to pass an array into that param, like this:


`{% set dateParam = ['and', '>= ' ~ year, '< ' ~ (year + 1)] %}`
Michael Rog
CC BY-SA 3.0
2016-03-10T14:52:26.950Z
Well, it does work like I wrote it.  But, it works the way you did it too.  I get the exact same results both ways. Interesting...  Keeping your way in my code though, it is definitely cleaner.
Eric Chantigny
CC BY-SA 3.0
2016-03-10T15:06:03.503Z
Cool. Where did you find the example/inspiration for feeding a string into the date param?
Michael Rog
CC BY-SA 3.0
2016-03-10T23:25:42.683Z
p.s. I double-checked with Brad. He confirmed that date parameters accept a string or an array by design: _DateFieldType_'s `modifyElementsQuery` calls `DbHelper::parseDateParam()` and the first thing that does is convert the value to an array if it's not one: https://github.com/pixelandtonic/Craft-Release/blob/master/app/helpers/DbHelper.php#L557 — Pretty cool!
Michael Rog
CC BY-SA 3.0
2016-03-12T00:30:59.367Z
I found it on another question here somewhere.  I can't remember how I found it though. I repurposed the answer to my situation and it worked.
Eric Chantigny
CC BY-SA 3.0
2016-03-09T21:50:22.337Z
2016-03-09T21:50:22.337Z
Eric Chantigny
<p>I have a date field (date) in my entry and I wish to get all entries of a specified year.  Can’t figure it out at all.  Here’s what I have now, to sort them by that field: </p>

<pre><code>craft.entries.section('evenements').order('date desc')
</code></pre>

<p>My "year" is passed to the page through routing and is named "year".  I can get that. </p>

<p>Thanks</p>

<entries><datetime><routing>
Displaying entires by year from a custom date field
# Displaying entires by year from a custom date field

(Asked by: username_0 on 2016-03-09)

I have a date field (date) in my entry and I wish to get all entries of a specified year.  Can’t figure it out at all.  Here’s what I have now, to sort them by that field: 
craft.entries.section('evenements').order('date desc')

My "year" is passed to the page through routing and is named "year".  I can get that. 
Thanks

**Tags:** entries, datetime, routing

---

## 1 answers

### Answer by username_0 on 2016-03-09. Score: 3 | Accepted answer

Looks like I finally found an answer to it
year being my param
date being my custom date field
{% set dateParam = 'and, >= ' ~ year ~ '-01-01, < ' ~ (year + 1) ~ '-01-01' %}

    {% for entry in craft.entries.section('evenements').order('date desc').date(dateParam) %}
        {{ entry.title }}
    {% endfor %}

> **Comments:**
> **username_1**: Curiously, does that work? I would think you'd need to pass an array into that param, like this:   `{% set dateParam = ['and', '>= ' ~ year, '< ' ~ (year + 1)] %}`  
> **username_0**: Well, it does work like I wrote it.  But, it works the way you did it too.  I get the exact same results both ways. Interesting...  Keeping your way in my code though, it is definitely cleaner.  
> **username_1**: Cool. Where did you find the example/inspiration for feeding a string into the date param?  
> **username_1**: p.s. I double-checked with Brad. He confirmed that date parameters accept a string or an array by design: _DateFieldType_'s `modifyElementsQuery` calls `DbHelper::parseDateParam()` and the first thing that does is convert the value to an array if it's not one: https://github.com/pixelandtonic/Craft-Release/blob/master/app/helpers/DbHelper.php#L557 — Pretty cool!  
> **username_0**: I found it on another question here somewhere.  I can't remember how I found it though. I repurposed the answer to my situation and it worked.  

---

