Date Subtraction

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 6, 2019   (RSS)

By KennyH - August 5, 2019

I am trying to add a stat counter that would take the year founded and subtract it from the current year then display the difference. 

In the code below, I tried replacing

'-2003 year'

with

-$page_elementsRecord['year_founded'] year

and I get "syntax error, unexpected 'year' (T_STRING), expecting ',' or ')' in /home/public_html/stats.php on line 27."

<strong data-to="<?php $date = date('Y');
$newdate = strtotime ( -$page_elementsRecord['year_founded'] year , strtotime ( $date ) ) ;
$newdate = date ( 'Y' , $newdate );
echo $newdate; ?>" data-append="+">0</strong>

If I remove - year then it just displays the year.

By KennyH - August 6, 2019

That works great, Daniel!