Repository navigation
BLL Time Recipes
Examples · date · time · Flow actions
Use timestamps for arithmetic and format only the final result.
now is the current evaluation's Unix timestamp in milliseconds.
date formats a calendar instant; time formats an elapsed duration.
The MQTT-to-spreadsheet discussion recommends Execute BLL-expression (as Tag) with:
nowPass the number tag to a log or spreadsheet card, or use the
variable-setting expression action to save it in a number variable such as
LastMessageTick. Record it when the event arrives, not later when an
export eventually runs.
For an API that expects Unix seconds, use:
Math.floor(now / 1000)This is an adaptation of the epoch-time question. The post uses rounding; flooring instead gives the count of completed seconds. Milliseconds and seconds are not interchangeable, and neither value is microseconds.
In this temperature-freshness discussion, the goal is to omit readings that are too old from averages and other calculations.
- Start with the event or scheduled trigger that needs a freshness check.
- Add Get variable properties for the BLL variable holding the reading.
- Add Execute BLL-expression (as Tag) after it. In its expression,
insert the Last Changed (UTC tick) token from step 2 and subtract it
from
now. - Divide the millisecond difference by
60000for minutes, then connect the numeric result to a threshold condition or report card.
The current source returns milliseconds since the Unix epoch for the numeric
tag labeled Last Changed (UTC tick); the label does not mean .NET ticks.
It is the time the BLL variable was last set, not proof that the physical
sensor produced a new reading. If repeated identical sensor reports must
refresh freshness, explicitly store now when each report arrives.
The original Flow demonstrates:
Historical Flow screenshot from the community discussion; the timestamp token is milliseconds, so use the current source behavior described above.
For a fixed sample timestamp, this bare expression calculates rounded minutes:
Math.round((now - 1762952400000) / 60000)Replace the numeric timestamp with the actual UTC tick tag. Use Math.floor
instead if you want completed minutes. Do not parse the localized datetime
tag when a numeric tick is available.
A freshness condition can compare milliseconds directly. This adaptation requires a sample to be neither in the future nor older than 15 minutes:
now >= 1762952400000 && now - 1762952400000 <= 15 * 60000Replace both sample timestamps with the same tick tag. The 15-minute threshold
is a choice for this example, not a BLL default. Check that the source has a
meaningful timestamp.
For receipt-based freshness, explicitly record now when a sensor report
arrives; do not assume a variable's metadata proves a new physical reading,
particularly when the incoming value stays unchanged.
Capture a numeric now at each event, then subtract the start tick from
the end tick. For example:
(new Date("2026-11-12T14:00:00Z").getTime() - new Date("2026-11-12T12:30:00Z").getTime()) / 60000The result is 90 minutes. This adaptation follows the
two-event time-difference discussion.
It also works across midnight because the date is part of each timestamp.
Do not subtract display strings such as 12:30 and 14:00.
For a formatted duration or the existing offset-aware example, see
time differences.
The expression card already supplies a number tag when it can convert the
result; an extra parseInt is not needed for that conversion.
In this solved energy-calculation question, the expression is:
date("m") / 60Use Set variable to BLL expression or the expression-as-tag card,
not the legacy Math.js expression card: date is a BLL helper.
At 15 minutes past the hour the result is 0.25. Seconds are not included.
This is a time fraction, not an energy measurement. Estimating a whole hour from partial-hour consumption requires assumptions about future use and handling for minute zero; avoid dividing by a zero fraction.
The 90-minute notification solution
uses date("shorttime", now + 90 * 60000). A task-start adaptation subtracts
a lead time instead:
date("HH:mm", new Date("2026-11-12T18:00:00+01:00").getTime() - 45 * 60000, "en-GB", "Europe/Amsterdam")This returns 17:15. Supply an actual dated target with an explicit offset;
formatting a calculated time does not itself schedule a Flow. Use a suitable
scheduler, for example Timey, for execution.
An elapsed 24 hours is not always one local calendar day across a daylight-saving change. Keep calculations and time-zone assumptions explicit.
Support development - If Better Logic Library is useful to you, you can support its
continued development through GitHub Sponsors,
Patreon,
PayPal, or
bunq.
Thank you!
