<p>I am working with a template in Craft 2, and I am setting up the criteria for entries to be displayed.<br />
Here is my code (below).</p>
<pre><code>{% set today = now|date('Y-m-d') %}

{% set criteria = {
    section: 'bulletin',
    order: 'postDate',
    expiryDate: '&gt;=' . today
} %}

{% set initialEntry = craft.entries(criteria).first() %}
{% set finalEntry = craft.entries(criteria).last() %}
</code></pre>
<p>I get this error:</p>
<pre><code>Impossible to access an attribute (&quot;today&quot;) on a string variable (&quot;&gt;=&quot;). 
</code></pre>
<p>How would I set expiryDate &gt;= today?</p>

CC BY-SA 4.0
2022-01-31T19:12:59.143Z
In Twig, `~` is the concatenation operator! You can also use `">= #{today}"`, which Twig refers to as "string interpolation." This looks fine, otherwise. 
August Miller
CC BY-SA 4.0
2022-01-31T19:42:52.357Z
Ah!  Thanks so much.  I was still in PHP mode.  :)
buck1112
<templating><entries><datetime><craft2>
Craft 2 - Date Comparison In Criteria - Impossible to access an attribute ("today") on a string variable (">=")
# Craft 2 - Date Comparison In Criteria - Impossible to access an attribute ("today") on a string variable (">=")

(Asked by: username_0 on 2022-01-31)

I am working with a template in Craft 2, and I am setting up the criteria for entries to be displayed.
Here is my code (below).
{% set today = now|date('Y-m-d') %}

{% set criteria = {
    section: 'bulletin',
    order: 'postDate',
    expiryDate: '>=' . today
} %}

{% set initialEntry = craft.entries(criteria).first() %}
{% set finalEntry = craft.entries(criteria).last() %}

I get this error:
Impossible to access an attribute ("today") on a string variable (">="). 

How would I set expiryDate >= today?

**Tags:** templating, entries, datetime, craft2
> **Comments:**
> **username_1**: In Twig, `~` is the concatenation operator! You can also use `">= #{today}"`, which Twig refers to as "string interpolation." This looks fine, otherwise.   
> **username_0**: Ah!  Thanks so much.  I was still in PHP mode.  :)  

---

## 0 answers

