Path

ez.no / ezpublish / documentation / customization / tips & tricks / find the age in years for an object


Find the age in years for an object

These documentation pages are no longer maintained. Please visit the new documentation site.

If you have an user, or any content object with an datefield, then you can use the following code to find the age in years for the object. Note the object must have an datefield called "born", or you must replace born in the code below with the name of your datefield.

{* Calculate the age for the user, find the difference in years, month and day from the current date *}
{let curr_ts=currentdate()
age=sub($curr_ts|datetime( custom, '%Y'),$node.object.data_map.born.data_int|datetime( custom, '%Y'))
res_m=sub($curr_ts|datetime( custom, '%m'),$node.object.data_map.born.data_int|datetime( custom, '%m'))
res_d=sub($curr_ts|datetime( custom, '%d'),$node.object.data_map.born.data_int|datetime( custom, '%d'))
}
{* age is now simply the difference in year, next is some logic to find out the difference relative to current month and day *}
{section show=$res_m|lt(0)}
{* Month, Less than zero, subtract one *}
{set age=$:age|dec}
{/section}
{section show=and($res_m|eq(0),$res_d|lt(0))}
{* Month is equal, check days, if less than zero subract one from year *}
{set age=$:age|dec}
{/section}
AGE IS {$age}
{/let}

Comments

Thanks !!!

You save me some time of coding, thank you very much !!

Contents

Customization

Access control
eZ publish API Documentation
Content structure
Custom design
Components
Tips & Tricks
    Debugging templates
    Javascript in templates
    Fetching current user
    Showing related objects
    Show which templates are used
    Fetching the ID of the parent
    One Article Folder
    Creating tree menus
    How can I use my own php script insid...
    Hiding attribute content
    Splitting an article over several pages
    Accessing section id in pagelayout
    List articles in folder
    Creating nice URLs
    Alt tag on images
    Improve the pagelayout.tpl
    Clean HTML tags
    Insert javascript call inside ezpub d...
    3rd party applications
    Fetch Function examples
    Display more than 15 items on your co...
    Including PHP files in templates
    Redirecting after content publishing
    HowTo see if article has an image
    Date and Time Formats
    Forms processing example: store user...
    Adjust Timezone
    Adding a Remove Button/Image
    Find the age in years for an object
    Editing, creating and removing conten...
    Indexing binary files with IFilters o...
Troubleshooting


Created

26/05/2004
12:27:51 pm
by Tore Skobba

Last updated

26/05/2004
12:33:38 pm
by Tore Skobba

Authors

Tore Skobba



This page is part of the eZ Publish documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.