CalcBuilder Forum

Date difference

User shaundobie 2018-07-18 17:42:19

Hello,

I am experiencing trouble finding the difference between two dates. I have tested the code on other php editors and it has worked fine.
The code I have used is as follows:
$tax_2018=date_create("2018-4-5");
$ysp = $tax_2018->diff($DofP);
$ysp=$ysp->y;

DofP is a date input field. I am trying to find the number of years between 2018-4-5 and the date entered into DofP.
Any help would be appreciated.
Thanks,
Sam

Moonsoft support 2018-07-19 10:14:32

Hello,
the right way to do it would depend on the date format you set for your input field. We suggest to try to convert it directly into a date

$ysp = $tax_2018->diff(date_create($DofP));

in case you have set that same date format you're using for the fixed date "2018-4-5"


Hope this helps, regards

User shaundobie 2018-07-19 14:14:15

That did the trick, many thanks.

...
Support/development

Perfect for small code changes or to correct any bug at your site

Buy now!
...
Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!