Calculating the number of days between two dates

An Advanced custom field can be used to calculate the number of days between two dates. This example code reads two dates from fields called ‘date1’ and ‘date2’, and assumes that the source dates is in the format DD-MM-YYYY.

To create an Advanced custom field:

  • right click in the EasyCatalog data panel and use the “New Custom Field” option on the pop-up menu that appears.
  • At the top of the dialog, give your new field a name.
  • Change the ‘Type’ popup to ‘Advanced’.
  • In the “Dependencies” field enter the names of the other fields this custom field depends on — in this case “date1,date2”. This will ensure that if either date1 or date2 are updated this custom field will be recalculated.