Hi, I have a page in which I need to put a custom field that I don't know how to output.
In a page there is a text that says: "today, 23 years later 1994, etc etc etc"
So, what I want to do is not writing "23" an each year update the page, but to put a custom field like "1994-today", soit always output the difference from 1994 and today year.
Toolset allows you to format the value of a custom date field using any Date and Time format provided by WordPress, but what you're describing is a calculation based on a fixed past date and "today". This will require custom code. You can use PHP's DateTime::diff function to calculate the difference between two DateTime objects, then format the result: hidden link
$datetime1 = new DateTime('1994-01-01');
$datetime2 = new DateTime('');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%y years since Jan 1, 1994.');
I see that your request is not a complicated one and we can offer a solution for you.
I see that Christian's solution is a good one according to the description you've provided.
If you want a better solution, it would be nice if you guided us to the solution you like.
If you don't mind, we will be happy to implement a solution for your request.
[format_date_difference start="1994-01-01" end="" format="%y years"] // 23 years
[format_date_difference start="1994-01-01" end="2010-05-31" format="%y years"] // 16 years
[format_date_difference start="1994-01-01"] // 23 years, 8 months, 18 days
[format_date_difference] // 0 years, 0 months, 0 days
These are the defaults, but you can change them in the $atts array above:
Default start: now
Default end: now
Default format: %y years, %m months, %d days