@now
A computed Date field that evaluates to the current timestamp at query time — not stored in the database.
A computed field that evaluates to the current timestamp at query time. The value is not stored in the database — it is computed fresh on every read.
Syntax
model Post {
id Record @id
title String
currentTime Date @now
}Behavior
- Date fields only —
@nowcan only be applied to fields of typeDate. - Computed, not stored — Defined as
COMPUTED time::now()in SurrealDB. The field does not exist in the stored record — it is evaluated each time the record is read. - Output-only — Because the value is computed by the database, it cannot be set in
createorupdateoperations. It is excluded fromCreateInput,UpdateInput, andWhereInputtypes. - Always present in output — The field is always returned when the record is read (unless excluded by
select).
Usage
const post = await client.db.Post.create({
data: { title: 'Hello World' },
// currentTime cannot be set — it's computed
});
// currentTime is always the current server time at read time
console.log(post.currentTime); // Date — e.g., 2025-01-15T10:30:00.000ZSince the value is computed on every read, it reflects the time the query was executed, not the time the record was created.
@now fields are excluded from WhereInput — you cannot filter by a computed field. They are also excluded from OrderBy types.
Model Fields Only
@now is only allowed on model fields. It is not allowed on object fields or tuple elements.
SurrealDB requires COMPUTED fields to be top-level — they cannot be defined on embedded object sub-fields or tuple elements. Use @createdAt or @updatedAt for timestamp fields within objects.
Allowed On
| Construct | Allowed |
|---|---|
| Model fields (Date) | ✅ |
| Object fields | ❌ |
| Tuple elements | ❌ |
| Enum values | ❌ |
| Literal fields | ❌ |
Mutual Exclusions
@now cannot be combined with any of these decorators on the same field:
@createdAt,@updatedAt— other timestamp decorators@default,@defaultAlways— custom default strategies@uuid,@uuid4,@uuid7— UUID auto-generation decorators@nullable— computed fields have no stored value to be null@readonly— SurrealDB does not supportREADONLYonCOMPUTEDfields
When to Use @now vs @createdAt vs @updatedAt
| Decorator | Stored | Set on create | Updated on write | Use case |
|---|---|---|---|---|
@now | No | N/A (computed) | N/A (computed) | Current server time at read |
@createdAt | Yes | Yes | No | Record creation timestamp |
@updatedAt | Yes | Yes | Yes | Last modification timestamp |
- Use
@createdAtfor timestamps that record when something was created. - Use
@updatedAtfor timestamps that track the last modification. - Use
@nowwhen you need the current server time at the moment of reading, not a stored value.