Home › Forums › General Issues › Calculate a member of staff’s years at company › Reply To: Calculate a member of staff’s years at company
Hey Darren,
Two stages to this, first of all create a function that will add the suffix to the number, so in your theme’s functions.php
file add the following:
function add_suffix( $n ) { $suffix = date( 'S', mktime( 1, 1, 1, 1, ( (($n>=10)+($n%100>=20)+($n==0))*10 + $n%10) )); return $n . $suffix; }
Then amend your code in the post/page by removing the line echo $interval->y. ‘ Year of Service’;
And then replace it with the two following lines:
$interval_with_suffix = add_suffix( $interval->y );
echo $interval_with_suffix . ' Year of Service';
I hope this helps, it’s been semi-tested, but no guarantees.
If you’re interested in learning about the suffix function there’s a detailed answer here. Credit to Andrew Kozak for the solution I’ve just modified the function slightly to return the original number as well as the suffix.
Cheers, Dan
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!
2022 was a big year for Advanced Custom Fields, with more capabilities, a new generation of ACF Blocks, a refreshed UI, and a new home. Our year in review post looks at advancements we’ve made and offers a glimpse of the future.
— Advanced Custom Fields (@wp_acf) January 6, 2023
https://t.co/HahJUCcyH4
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.