Date comparison functions (dateDiff)
You can use a dateDiff function to compare dates and return the number of days between these dates. For example, you might want to charge a premium for orders that need to be completed faster than your standard processing time.
To calculate the difference between the creation date and the due date:
- d1 — the later date (due date)
- d2 — the earlier date (creation date)
This function returns the time in milliseconds, so you need to convert milliseconds into days by dividing the return value by (1000 * 60 * 60 * 24).
If you want to charge an extra $7.50 for orders that are required in 2 days or less, you would firstly define the above function to determine the difference between the creation date and due date. You would then define a deliveryCost variable in your estimateCost(order) function, as follows:
You cannot reference lead time or working days in your cost scripts as there are no Order object attributes for these values.