How to format dates and calculate time differences

Modified on Thu, 4 Dec at 11:33 AM

How to format dates and calculate time differences

Hubhus provides a comprehensive set of tools for working with dates and times in templates, booking forms, and automations.

On this page

Jump to any section using the links below

Hubhus provides a comprehensive set of tools for working with dates and times in templates, booking forms, and automations. This includes system timestamps, localized formatting, parsing, rounding, and date-time input fields with configurable behaviour. This article explains how to use the available placeholders and components to format dates, calculate differences, and configure date-time inputs.


1. System timestamp placeholders

These give you the current date or datetime in Hubhus’ strict database format.

Current datetime (Y-m-d H:i:s):

%timestamp%

Current date (Y-m-d):

%timestamp_date%

Use these for automation logic, storing values, or generating consistent timestamps.


2. Parsing dates with @str2datetime

You can convert English text into a strict datetime value using:

@str2datetime[text]

Examples:

@str2datetime[now] @str2datetime[tomorrow 14:00] @str2datetime[first day of next month] @str2datetime[+7 days]

The output is always in strict format: YYYY-MM-DD HH:MM:SS.


3. Language formatting (DK formats)

Hubhus includes helpers for user-friendly, Danish-formatted output.

Date only:

@date_dk[%event_start_date_db%]

Date and time:

@datetime_dk[%event_start_datetime_db%]

Time only:

@time_dk[%event_start_datetime_db%]

These are ideal for emails sent to customers.


4. Formatting dates using <hh-date.format>

To format any date value:

<hh-date.format input="%event_start_datetime_db%" />

Hubhus automatically formats the value based on system conventions.


5. Displaying date ranges with <hh-date.interval>

Use this component to present a start and end time cleanly:

<hh-date.interval from="%event_start_datetime_db%" to="%event_end_datetime_db%" />

Customers will see a readable “from–to” interval.


6. Calculating time differences with <hh-date.diff>

To compute differences between two dates:

<hh-date.diff from="%lead_created_at%" to="%event_start_datetime_db%" unit="days" absolute />

Supported units include:

  • seconds

  • minutes

  • hours

  • days

Use this for delays, reminders, or workflow timing logic.


7. Rounding dates (ceil, floor, round)

Hubhus can align datetimes to minute-based intervals. Examples:

Round up:

<hh-date.ceil input="now" precision="15" unit="minute" />

Round down:

<hh-date.floor input="now" precision="15" unit="minute" />

Round to nearest:

<hh-date.round input="now" precision="15" unit="minute" />

Useful for working with booking-slot intervals (for example, 5-, 10-, or 15-minute increments).


8. Formatting numeric calculations with <hh-number.format>

If you output numeric durations or other calculated values, you can control decimal formatting:

<hh-number.format input-decimal-separator="." output-decimal-separator="," decimals="2" />

This is optional but helpful when presenting numeric values in emails.


9. Working with date-time input fields in forms

Hubhus provides a dedicated input type for selecting both date and time:

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

This creates a combined date/time picker with support for multiple configuration attributes.

Supported data-* attributes

AttributeDescriptionTypical values
data-formatDisplay format for date/timeyyyy-mm-dd hh:ii
data-minute-stepMinute increments1, 5, 10, 15
data-start-dateEarliest selectable valueDate string
data-end-dateLatest selectable valueDate string
data-min-viewLowest view (hour/day)0 or "hour"
data-max-viewHighest view (year/month)4 or "year"
data-week-startFirst day of week0 or 1
data-autocloseClose on selectiontrue/false
data-today-btnShow "Today" buttontrue/false
data-force-parseParse typed inputtrue/false


Common configuration recipes

15-minute steps, Monday as week start:

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

Allow only next 30 days:

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

Date-only input (no time selection):

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

Show Today button and autoclose:

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

Important notes

  • Ensure that data-format matches any prefilled value

  • Keep minute steps consistent with your booking intervals

  • Use strict formats (Y-m-d H:i:s) when working with automations


Summary

Hubhus offers a complete set of tools for handling dates and times:

  • System timestamps

  • English-to-datetime parsing

  • Localized DK formatting

  • Date interval display

  • Time difference calculation

  • Rounding to specific intervals

  • Configurable date-time input fields

  • Optional numeric formatting

These tools make it easy to work with dates in emails, automations, booking flows, and internal templates.

? Common searches

web form • form setup • booking form • form builder

? Also known as

web form • input form • data capture

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article