TYPO3 Fluid Date Format (Times Ago)

Are you looking for "X times ago" display for TYPO3 Fluid's date format? In this TYPO3 tutorial, Learn how to achieve it.

TYPO3 Fluid Date Format (Times Ago)

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}'}" />

Looking for the Right TYPO3 Products for Your Project?

Explore professional products from T3Planet Shop, including TYPO3 templates, TYPO3 extensions, and AI-powered extensions for modern TYPO3 websites.

  • TYPO3 Templates for flexible and scalable websites
  • TYPO3 Extensions for added features and functionality
  • AI Extensions for content, search, accessibility, localization, and automation
  • Free & Premium products for different TYPO3 project needs
Explore T3Planet Shop
T3Planet Shop TYPO3 Products

Post a Comment

×