Is it possible to compare a post's date to now?

I’ve been using the Archive code

{% for year, posts in section.pages | group_by(attribute="year") %}
    <h2>{{ year }}</h2>

    {% for post in posts %}
        <li><a href="{{ post.permalink }}">{{ post.title }}</a></li>
    {% endfor %}
{% endfor %}

to list the blog posts I’ve written and it works great.

However, now I want to filter out posts that are post-dated (having a date property in the future). This way I could do scheduled releases without having to use draft and redeploying.

Any ideas?

1 Like

I did not find anything more straightforward than this:

{% for page in section.pages %}
	{% if %}
		{% set page_time =|date(format="%s")|int %}
		{% set curr_time = now()|date(format="%s")|int %}
		{% if page_time < curr_time %}
		Hello from the past
		{% else %}
		Hello from the future
		{% endif %}
	{% endif %}
{% endor %}

But it works.


Probably the only way to do it currently yes


It would be nice to add a timestamp filter to Tera to allow something like:

{% if | timestamp > now(timestamp=true) %}

By the way, Tera supports now() as timestamp :

And of course it would be nice to have native date comparison :

{% if > now(timestamp) %}

@keats it would be great to have a simple working date comparison mechanism. And/or provide some strings comparison mechanism.