Moonsoft Software Solutions

Date difference

Started 18 Jul 2018 · 2 replies

  1. 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
  2. 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
  3. shaundobie
    That did the trick, many thanks.

Still stuck?

Customers with an active license can open a support ticket.

Log in to open a ticket