Datetime

A Datetime wraps an ISO 8601 datetime string for use with SurrealDB's datetime type. It preserves the original string representation through serialization and deserialization.

Import

from surrealdb import Datetime

Constructor

Syntax

Datetime(dt)
ParameterTypeDescription
dt strAn ISO 8601 datetime string.

Examples

dt = Datetime("2025-01-15T10:30:00Z")
dt = Datetime("2025-06-01T14:00:00.000+02:00")

Properties

PropertyTypeDescription
dtstrThe ISO 8601 datetime string.
dt = Datetime("2025-01-15T10:30:00Z")
print(dt.dt) # "2025-01-15T10:30:00Z"

Usage

from surrealdb import Surreal, RecordID, Datetime

db = Surreal("ws://localhost:8000")
db.connect()
db.use("my_ns", "my_db")
db.signin({"username": "root", "password": "root"})

db.create("events", {
"title": "Launch",
"scheduled_at": Datetime("2025-06-01T09:00:00Z"),
})

See Also