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
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.