Date Subtraction

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

By daniel - August 6, 2019

Hi KennyH,

The syntax error here is being caused by some issues with string formatting. Strings need to be within quotation marks (either single or double) and can be joined with variables using a period. The correct way to write this would be:

$newdate = strtotime ( "-" . $page_elementsRecord['year_founded'] . " year" , strtotime ( $date ) ) ;

This may give you the result you want, though if all you need is the difference between two years you could likely also simplify it and just use a subtraction, something like this:

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

Let me know if you're able to fix the issue, or have any other questions!

Thanks,

Daniel
Technical Lead
interactivetools.com

By KennyH - August 6, 2019

That works great, Daniel!