How do I compare a date field with the current time in a twig template? I have a date field on a node – set to a custom date format (c which is ISO) in the Manage Display.
I have a twig template checking to see if that date field comes before today, in which is should output Past.
Outputting the fields/comparison values gets me the properly formatted dates I want to compare.
{{ content.field_closing_date.0 }}
{{ 'now'|date('c') }}

which outputs
2021-05-05T16:30:00-07:00
2021-05-14T12:01:53-07:00

My comparison is
{% if 'now'|date('c') &gt; content.field_closing_date.0 %}
Past
{% endif %}

But it's not outputting Past. What gives?
You can see that the todays date does come after the date field.
If you feel like a preprocess function is overload and if you can afford to ignore timezones, try converting both date values to Unix timestamps to make them properly comparable. And prefer raw node values over formatted content values:
{% if ('now'|date('U') &gt; node.field_closing_date.0.value|date('U')) %}
  Past
{% endif %}