Skip to main content
CalcBuilder logo
CalcBuilder Forum

Date difference

User shaundobie

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

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

That did the trick, many thanks.

...
Support/development 10 hours

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

Buy now!
...
CalcBuilder

Create dynamic calculators

Buy now!