All,
I have the following PHP code to determine how many years apart two dates are on my WordPress page:
<?php
$date1 = new DateTime("2003-03-24");
$current_date = new DateTime(date("Y-m-d"));
$interval = $date1->diff($current_date);
echo $interval->y;
?>
I installed the Exec-PHP plugin for WordPress to display this properly. However when I try and display my page I get the following error:
Fatal error: Call to undefined method DateTime::diff() in
/home/person/test.website.com/wp-content/plugins/exec-php/includes/runtime.php(42)
: eval()’d code on line 7
How can I get this to work properly? Thanks!
I remember this question a while back: How to calculate the difference between two dates using PHP?
With some small adjustments it looks like this:
Output:
Number to letters function modified from this site: http://www.phpro.org/examples/Convert-Numbers-to-Words.html