Compare dates in Twig
7
In Twig you can use "now" | date
to get the current date. Format "now" and your date as unix-timestamp. You can then rely on number comparision to compare dates this way:
{% if record.end_date|date('U') > 'now'|date('U') %}
A nicer solution to this problem is to add a getIsPastAttribute
method to your model and do the comparision there. This way you can use record.is_past
in twig.
class Record extends Model
{
public function getIsPastAttribute()
{
return $this->end_date->lt(now());
}
}
There are no comments yet
Be the first one to comment