1

I'm trying to display how long til a certain post expires depending on a date/time field.

Example

Expires in 13 days.

My field is currently displayed by doing {{ entry.expiration }}

I just don't know how I would just display the days remaining until this date.

Thanks

3

Your entry.expiration is actually an object of type DateTime thus you'll have the full power of PHPs DateDiff functionality

$interval = $datetime1->diff($datetime2);

In Twig this is something like

{% set difference = now.diff(entry.expiration) %} 
{{ difference.format('%R%a days') }} 

now should be the current date

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.