TYPO3 Fluid Date Format (Times Ago)

Kategorie : Fluid , By : Sonal Chauhan

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:else if="{diff} < 3600">
            <f:format.number decimals="0">{diff / 60}</f:format.number> minute ago
        <f:else if="{diff} < 86400">
            <f:format.number decimals="0">{diff / 3600}</f:format.number> hours ago
        <f:else if="{diff} < 604800">
            <f:format.number decimals="0">{diff / 86400}</f:format.number> days ago
        <f:else if="{diff} < 2419200">
            <f:format.number decimals="0">{diff / 604800}</f:format.number> weeks ago
        <f:else if="{diff} < 29030400">
            <f:format.number decimals="0">{diff / 2419200}</f:format.number> months ago
        <f:else>{f:format.date(date: '{posted}',format:'%d %B, %Y')}</f:else>


Step 2. Call timeAgo TYPO3 Fluid Section


<f:render section="timeAgo" arguments="{posted:'{posting.datePosted}'}" />

To keep improving, Do you have feedback and suggestions? Or, Are you facing any issues to implement above TYPO3 tutorial? Feel free to write your comment at below comment box; I'll happy to help you :)

Post Comment

Your email address will not be published. Required fields are marked *


Name ist erforderlich!

Geben Sie einen gültigen Namen ein

Gültige E-Mail ist erforderlich!

Gib eine gültige E-Mail Adresse ein

Kommentar ist erforderlich!

Google Captcha ist erforderlich!

Sei der erste der kommentiert

Stay up to date with our recent TYPO3 Blogs, news, & updates