Calculations & constants
The templating engine provides built-in constants and functions for date handling and arithmetic — no custom data binding required.
The current date (now)
@now is a built-in constant that resolves to the server's current date and time, formatted as yyyy-MM-dd HH:mm:ss. You can offset it by an amount and unit, and pipe it through dateFormat for display.
Parameters
| argument | type | description |
|---|---|---|
| amount | number | Amount to offset (positive or negative) |
| qualifier | string | Unit: years/y, months/mm, days/d, hours/h, minutes/m, seconds/s, milliseconds/ms |
Example — assume current date/time is 2025-07-22 08:00:00
{{ @now }} -> '2025-07-22 08:00:00'
{{ @now(-2, hours) }} -> '2025-07-22 06:00:00'
{{ @now(-30, minutes) }} -> '2025-07-22 07:30:00'
{{ @now | dateFormat:'dd-MM-yyyy' }} -> '22-07-2025'
Useful for stamping the document generation time on invoices and notifications.
Date difference
Calculates the difference between two dates. Assumes date1 is before date2; returns a negative number otherwise.
dateDiff date1 date2 operator fractionalResult
| argument | type | description |
|---|---|---|
| date1 | string | Start date/time |
| date2 | string | End date/time |
| operator | string | Unit: year, month, week, day, hour, minute, second |
| fractionalResult | boolean | Optional: 'true' to return a decimal result |
Example — port stay from arrival to departure
{{dateDiff '2025-07-20 06:00:00' '2025-07-22 18:30:00' 'days' }} => 2
{{dateDiff '2025-07-20 06:00:00' '2025-07-22 18:30:00' 'days' 'true' }} => 2.52083333...
{{dateDiff '2025-07-20 06:00:00' '2025-07-22 18:30:00' 'hours' }} => 60
Math
Performs a simple arithmetic operation on two values.
math number operator value
| argument | type | description |
|---|---|---|
| number | string | The base number |
| operator | string | One of: +, -, *, / |
| value | string | The second operand |
Example
{{math 75000 '*' 0.05 }} => 3750 (5% port dues on 75,000 t cargo)
{{math 1250 '/' 4 }} => 312.5 (split invoice across 4 customers)
{{math 48 '+' 12 }} => 60 (total transit hours)
Math over a list (mathArray)
Performs an aggregate calculation (sum, average, min, max, count, or sumproduct) over an array.
mathArray value method property
| argument | type | description |
|---|---|---|
| value | array | The array to aggregate |
| method | string | One of: average, count, max, min, sum, sumproduct |
| property | string | The field to read from each item (omit for simple value arrays) |
Example
Considering the following data:
{
shipments: [
{ "vessel": "Ocean Star", "customer": "Blue Tide Shipping", "tonnage": 52000 },
{ "vessel": "Blue Marlin", "customer": "Maas Bulk", "tonnage": 38000 },
{ "vessel": "Nordic Wind", "customer": "Delta Logistics", "tonnage": 71000 },
{ "vessel": "Cape Horn", "customer": "Maas Bulk", "tonnage": 45000 }
],
portCalls: [4, 7, 3, 6]
}
{{mathArray shipments 'count' }} => 4
{{mathArray shipments 'sum' 'tonnage' }} => 206000
{{mathArray shipments 'average' 'tonnage' }} => 51500
{{mathArray shipments 'min' 'tonnage' }} => 38000
{{mathArray shipments 'max' 'tonnage' }} => 71000
{{mathArray portCalls 'sum' }} => 20