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 DatetimeConstructor
Syntax
Datetime(dt)Parameter | Type | Description |
|---|---|---|
dt | str | An ISO 8601 datetime string. |
Examples
dt = Datetime("2025-01-15T10:30:00Z")dt = Datetime("2025-06-01T14:00:00.000+02:00")Properties
| Property | Type | Description |
|---|---|---|
dt | str | The 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
Data types, All SDK data types
Duration, Duration type with unit conversion