Skip to content

Commit 8bc3491

Browse files
committed
Calc date functions
1 parent 9d8c8d8 commit 8bc3491

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/templates/template-variables.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,53 @@ Min/Max:
412412
- `ROUND(number, [places])` - Rounds a number to a specified number of decimal places. If places is omitted, it defaults to 0.
413413
- `SUM(number1, number2, ...)` - Returns the sum of a set of numbers.
414414
- `RAND()` - Returns a random number between 0 (inclusive) and 1 (exclusive).
415+
416+
### Date functions
417+
418+
All date functions work with ISO 8601 date strings (e.g., "2025-09-26" or "2025-09-26T12:00:00Z") and use UTC by default with optional timezone support.
419+
420+
#### Current time
421+
- `NOW([timezone])` - Returns the current date and time in ISO format (e.g., "2025-09-26T12:00:00.000Z")
422+
- `TODAY([timezone])` - Returns the current date in ISO format (e.g., "2025-09-26")
423+
424+
#### Date arithmetic
425+
- `DATEADD(date, value, unit, [timezone])` - Adds/subtracts time from a date
426+
- Units: "years", "quarters", "months", "weeks", "days", "hours", "minutes", "seconds"
427+
- `DATEDIFF(start_date, end_date, unit, [timezone])` - Calculates difference between dates
428+
- Returns floor of the difference (e.g., 1.9 months = 1)
429+
430+
#### Date components
431+
- `YEAR(date, [timezone])` - Extract year (e.g., 2025)
432+
- `MONTH(date, [timezone])` - Extract month (1-12)
433+
- `DAY(date, [timezone])` - Extract day of month (1-31)
434+
- `HOUR(date, [timezone])` - Extract hour (0-23)
435+
- `MINUTE(date, [timezone])` - Extract minute (0-59)
436+
- `SECOND(date, [timezone])` - Extract second (0-59)
437+
- `WEEKDAY(date, [type], [timezone])` - Get day of week
438+
- `type=1`: Sunday=1, Saturday=7 (Excel default)
439+
- `type=2` or omitted: Monday=1, Sunday=7 (ISO)
440+
- `type=3`: Monday=0, Sunday=6
441+
442+
#### Week calculations
443+
- `WEEKNUM(date, [type], [timezone])` - Get ISO week number of the year
444+
445+
#### Examples
446+
447+
```handlebars
448+
<!-- Add 14 days to order date -->
449+
Delivery date: {{ calc "DATEADD(order.date, 14, \"days\")" }}
450+
451+
<!-- Calculate age -->
452+
Age: {{ calc "DATEDIFF(birthDate, TODAY(), \"years\")" }} years old
453+
454+
<!-- Extract components -->
455+
Year: {{ calc "YEAR(invoice.date)" }}
456+
Month: {{ calc "MONTH(invoice.date)" }}
457+
458+
<!-- Business logic -->
459+
Due date: {{ calc "DATEADD(invoice.date, payment.terms, \"days\")" }}
460+
Overdue: {{ calc "DATEDIFF(invoice.dueDate, TODAY(), \"days\") < 0" }}
461+
462+
<!-- Timezone handling -->
463+
Local date: {{ calc "TODAY(\"Europe/Helsinki\")" }}
464+
```

0 commit comments

Comments
 (0)