Are you looking for "X times ago" display for TYPO3 Fluid's date format? In this TYPO3 tutorial, Learn how to achieve it. We can configure any Date Format by <f:format.date> view helper, but it's a bit difficult to get the in the format of "Times Ago" with reference to the current time.
Step 1. Create TYPO3 Fluid Section call "timeAgo"
<f:section name="timeAgo">
<f:variable name="now" value="{f:format.date(date: 'now',format:'%s')}" />
<f:variable name="posted" value="{f:format.date(date:'{posted}',format:'%s')}" />
<f:variable name="diff" value="{now - posted}" />
<f:if condition="{diff} < 60">
<f:then>Now</f:then>
<f:else if="{diff} < 3600">
<f:format.number decimals="0">{diff / 60}</f:format.number> minute ago
</f:else>
<f:else if="{diff} < 86400">
<f:format.number decimals="0">{diff / 3600}</f:format.number> hours ago
</f:else>
<f:else if="{diff} < 604800">
<f:format.number decimals="0">{diff / 86400}</f:format.number> days ago
</f:else>
<f:else if="{diff} < 2419200">
<f:format.number decimals="0">{diff / 604800}</f:format.number> weeks ago
</f:else>
<f:else if="{diff} < 29030400">
<f:format.number decimals="0">{diff / 2419200}</f:format.number> months ago
</f:else>
<f:else>{f:format.date(date: '{posted}',format:'%d %B, %Y')}</f:else>
</f:if>
</f:section>
Step 2. Call timeAgo TYPO3 Fluid Section
<f:render section="timeAgo" arguments="{posted:'{posting.datePosted}'}" />
Post a Comment