PHilgarth
PHilgarth

Reputation: 285

TYPO3 FLUID Template - how to get the difference in days between a timestamp and the current date

I need to calculate the difference in days between a given date and the current date.

I've created a mask element, where I can provide a date. In my template I want to output something like "published 2 days ago"

I've tried this:

<f:if condition="{data_item.tx_mask_date}">
    <p class="ww-teaserbox__date">
        <f:variable name="now" value="{f:format.date(date: 'now', format: 'Y-m-d')}" />
        <f:variable name="publish" value="{f:format.date(date: data_item.tx_mask_date, format: 'Y-m-d')}" />
        {f:format.date(date: now, format: 'Y-m-d') - f:format.date(date: publish, format: 'Y-m-d') }
    </p>
</f:if>

But that just outputs {f:format.date(date: now, format: 'Y-m-d') - f:format.date(date: publish, format: 'Y-m-d') }.

I hope anyone can help me here, thanks in advance.

Upvotes: 0

Views: 963

Answers (1)

Georg Ringer
Georg Ringer

Reputation: 7939

Even though fluid can do some basic calculations this is not really possible.

I suggest using a custom ViewHelper with 2 arguments and do the calculcation like this https://stackoverflow.com/a/26225650/2389552

Upvotes: 1

Related Questions