Support

Account

Home Forums General Issues Calculate Age from Date field Reply To: Calculate Age from Date field

  • Hi,

    I have been trying to calculate a member of staff’s years of service and have had some success following this guide 🙂

    This is working great, however, I would really like to display the result as “14th Year of Service” or “3rd Year of Service” and can’t figure it out could you offer some guidance please? I have been looking into it and it looks like oridnal suffix is what I am looking for.

    My PHP code is:

    <p class=”start-date”> <?php if( get_sub_field(‘startdate’) ): ?> <?php $date = get_sub_field(‘startdate’); $yearsofservice = new DateTime($date); $interval = $yearsofservice->diff(new DateTime); echo $interval->y. ‘ Year of Service’; ?></p> <?php endif; ?>

    Thank you in advance

    Darren