Skip to content

TIMESTAMP Entity

Feature Since Version Notes
TIMESTAMP WITH "<format>" >1.5.1 Represents the current time
Built-in formats (UTC, ISO, UNIX, UNIX-MS) >1.5.1 Standard time representations
Custom format strings >1.5.1 User-defined time formats

Overview

  • Description: Provides the current date and time in various predefined or custom formats. This entity can dynamically generate timestamps for use within actions or model definitions in LOT.

Signature

  • Syntax:
    TIMESTAMP WITH "<format>"
    
    (Note: Older versions might accept TIMESTAMP "<format>")

Supported Formats

Built-in Formats

Format Description Example Output Since Version
"UTC" Universal Coordinated Time YYYY-MM-DD HH:MM:SS (approx) >1.5.1
"ISO" ISO 8601 Format YYYY-MM-DDTHH:MM:SS.sssZ >1.5.1
"UNIX" Unix Timestamp (seconds) 1678886400 >1.5.1
"UNIX-MS" Unix Timestamp (milliseconds) 1678886400123 >1.5.1

Custom Format Strings

You can define a custom date-time format using special characters to specify date and time components.

Symbol Description Example
yyyy 4-digit year 2025
MM 2-digit month (01-12) 03
dd 2-digit day (01-31) 17
HH 24-hour clock hour (00-23) 14
mm Minute (00-59) 25
ss Second (00-59) 30
fff Milliseconds (000-999) 123
tt AM/PM designator PM
zzz Timezone offset +00:00
dddd Full weekday name Monday
MMM Abbreviated month name Mar
MMMM Full month name March

Example Custom Formats:

  • "yyyy/MM/dd HH:mm:ss"2025/03/17 14:25:30
  • "dd-MM-yyyy"17-03-2025
  • "HH:mm:ss.fff"14:25:30.123
  • "MM-dd-yyyy HH:mm:ss tt"03-17-2025 02:25:30 PM
  • "dddd, dd MMMM yyyy"Monday, 17 March 2025
  • "ddd, dd MMM yyyy"Mon, 17 Mar 2025

Compatible Keywords

  • SET: Stores the generated timestamp into a variable.
  • PUBLISH TOPIC: Publishes timestamp data externally.
  • KEEP TOPIC: Stores timestamp data internally.
  • REPLACE: Inserts dynamically generated timestamps into strings.
  • ADD (within Models): Adds a timestamp property.

Return Value

  • Description: Returns a formatted string representing the current timestamp based on the specified format.

Usage Examples

Basic Example

Publishes current timestamp in ISO format every 10 seconds:

DEFINE ACTION PublishTimestampISO
ON EVERY 10 SECONDS DO
    PUBLISH TOPIC "time/iso" WITH TIMESTAMP WITH "ISO"
Output Example: Publishes: 2025-03-17T14:25:30.123Z (Actual value will vary)

Intermediate Example

Stores a UNIX timestamp internally for device event logging:

DEFINE ACTION LogEvent
ON TOPIC "device/event" DO
    KEEP TOPIC "event/log" WITH TIMESTAMP WITH "UNIX"
Output Example: Stores internally: 1742193930 (Actual value will vary)

Advanced Example with Custom Format

Publishes a detailed timestamp for precise monitoring:

DEFINE ACTION DetailedMonitoringTimestamp
ON EVERY 1 MINUTE DO
    PUBLISH TOPIC "monitoring/timestamp" WITH TIMESTAMP WITH "yyyy-MM-dd HH:mm:ss.fff"
Output Example: Publishes: 2025-03-17 14:25:30.123 (Actual value will vary)

Usage with REPLACE

Inserting dynamic timestamps into message strings:

DEFINE ACTION DynamicTimestampMessage
ON TOPIC "alerts/generate" DO
    SET "AlertMessage" WITH REPLACE "<timestamp>" WITH TIMESTAMP WITH "UTC" IN "Alert triggered at <timestamp>"
    PUBLISH TOPIC "alerts/messages" WITH {AlertMessage}
Output Example: Publishes: Alert triggered at 2025-03-17 14:25:30 (Actual value will vary)

Weekday and Month Name Example

Publishes a readable date including weekday and month names:

DEFINE ACTION ReadableDate
ON EVERY 1 DAY DO
    PUBLISH TOPIC "daily/date" WITH TIMESTAMP WITH "dddd, dd MMMM yyyy"
Output Example: Publishes: Monday, 17 March 2025 (Actual value will vary)

Example in Models

Adding Timestamp in a Model:

DEFINE MODEL DataWithTimestamp WITH TOPIC "processed/data"
    ADD "value" WITH TOPIC "raw/data" AS TRIGGER
    ADD "receivedAt" WITH TIMESTAMP WITH "UNIX-MS"

Notes & Additional Information

  • Timezone: All built-in formats use Coordinated Universal Time (UTC). The timezone for custom formats depends on the broker's system time configuration.
  • Custom Formats: Ensure your custom string follows correct formatting symbols as indicated above. Incorrect custom formats may result in an empty string or unexpected output.

Related Documentation