# How to format dates and calculate time differences

URL: https://help.hubhus.com/kb/how-to-format-dates-and-calculate-time-differences
Category: Campaigns & Lead Management / Templates
Updated: 2026-09-28T14:40:40.697+00:00

Summary: System timestamps: %timestamp% (Y-m-d H&#58;i&#58;s), %timestamp_date% (Y-m-d). Parse text: @str2datetime&#91;now&#93; , @str2datetime&#91;tomorrow 14:00&#93; . Format: &lt;hh-date.format value="..." format="dd/MM/yyyy" /> . Date range: &lt;hh-date.interval> . Difference: &lt;hh-date.diff> . Round: &lt;hh-date.ceil/floor/round> . DK format: @dateformat_da&#91;...&#93; .

Hubhus provides built-in date tools for use in templates, booking forms, and automations - formatting, parsing, calculating differences, rounding, and working with date-time input fields.

## 7 date tools to know

1. **System timestamp placeholders**. `%timestamp%` → current datetime (Y-m-d H&#58;i&#58;s). `%timestamp_date%` → current date (Y-m-d). Use for automation logic, storing timestamps in fields, or consistent datetime generation.
2. **Parsing dates with @str2datetime**. Convert English text into strict datetime: `@str2datetime[now]`, `@str2datetime[tomorrow 14:00]`, `@str2datetime[first day of next month]`, `@str2datetime[+7 days]`. Useful for computing relative dates in automations and field values.
3. **Formatting dates with hh-date.format**. `<hh-date.format value="%lead_event_start%" format="dd/MM/yyyy" />` - display a stored date in a human-readable format. Common formats: `dd/MM/yyyy`, `yyyy-MM-dd`, `dd. MMMM yyyy`, `HH:mm`. Use DK-specific formatting with `@dateformat_da[date]`.
4. **Date ranges with hh-date.interval**. `<hh-date.interval from="..." to="..." />` - display a formatted date range (e.g. "Mon 5. May - Fri 9. May"). Useful in booking confirmations and event summaries.
5. **Calculating differences with hh-date.diff**. `<hh-date.diff from="..." to="..." unit="days" />` - calculate the difference between two dates. Units: `days`, `hours`, `minutes`. Use in confirmation emails ("Your appointment is in 3 days") or automation conditions.
6. **Rounding dates (ceil/floor/round)**. `<hh-date.ceil value="..." unit="hour" />` - round up/down/nearest to hour, day, week, month. `ceil` = round up, `floor` = round down, `round` = nearest. Useful for slot calculations and time window logic.
7. **Date-time input fields in forms**. Configure date/time picker inputs with `data-*` attributes: `data-datepicker` (enable picker), `data-min-date`/ `data-max-date` (restrict range), `data-default-value` (pre-fill). Example: pre-fill with computed date using `<hh-date.calculate>` in a hidden input.

**Read more**

### Date-time input field - syntax and attributes

Base syntax:

```
@input[date-time-strict; id='my-datetime'; data-minute-step='15']
```

**Supported data-* attributes:**

- `data-format` - display format for the picker (e.g. `yyyy-mm-dd hh:ii`)
- `data-minute-step` - minute increment steps: 1, 5, 10, or 15
- `data-start-date` - earliest selectable date (date string)
- `data-end-date` - latest selectable date (date string)
- `data-min-view` - lowest zoom level: 0 (hours) or 1 (days)
- `data-max-view` - highest zoom level: 3 (months) or 4 (years)
- `data-week-start` - first day of week: 0 (Sunday) or 1 (Monday)
- `data-autoclose` - close picker after selection: true/false
- `data-today-btn` - show "Today" shortcut button: true/false
- `data-force-parse` - parse typed input: true/false

### Configuration recipes

**15-minute steps with Monday as week start:**

```
@input[date-time-strict; data-minute-step='15'; data-week-start='1']
```

**Allow only the next 30 days:**

```
@input[date-time-strict; data-start-date='%now%'; data-end-date='%now_plus_30d%']
```

**Date-only input (hide time selection):**

```
@input[date-time-strict; data-min-view='1'; data-max-view='1']
```

**Show Today button and auto-close on selection:**

```
@input[date-time-strict; data-today-btn='true'; data-autoclose='true']
```

### DK date formatting helpers

For user-friendly Danish output in emails and templates:

```
@date_dk[%event_start_date_db%]         <!-- date only -->
@datetime_dk[%event_start_datetime_db%] <!-- date and time -->
@time_dk[%event_start_datetime_db%]     <!-- time only -->
```

Important notes for input fields:

- Ensure `data-format` matches the format of any pre-filled value
- Keep minute steps consistent with your booking slot intervals
- Always use strict format (Y-m-d H&#58;i&#58;s) when storing to fields used in automations

## Related articles

- https://help.hubhus.com/kb/how-to-calculate-values-and-format-numbers-in-templates
- https://help.hubhus.com/kb/hh-components-reference-guide
- https://help.hubhus.com/kb/understanding-placeholders-and-dynamic-content
- https://help.hubhus.com/kb/how-to-set-up-automations
