> For the complete documentation index, see [llms.txt](https://codemash.gitbook.io/codemash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codemash.gitbook.io/codemash/cloud/database/schema/field-types/date.md).

# Date and date-time

A date or date-time field stored as unix epoch seconds, with fixed bounds in the data schema and relative bounds in the UI schema.

A **Date** field stores a moment as **unix epoch seconds** (an integer). The `date` widget picks a day, the `datetime` widget a day and a time. Fixed bounds are data rules; bounds relative to today are form hints.

**Builder:** Form fields panel → **Date / Date & time** · widget `date` / `datetime` · data type `date.schema.v1`

## Data schema

```json
{
  "publishedOn": {
    "type": "integer",
    "minimum": 16777216,
    "maximum": 1893456000,
    "default": 1700000000
  }
}
```

| Keyword   | Required | What it does                                                                                                                                                                             | Example                          |
| --------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
| `type`    | yes      | Always `"integer"`.                                                                                                                                                                      | `"integer"`                      |
| `minimum` | **yes**  | The earliest moment allowed, in epoch seconds, **at least 16777216** (that is what makes the field a date and not an [Integer](/codemash/cloud/database/schema/field-types/integer.md)). | `16777216` (no real lower bound) |
| `maximum` | no       | The latest moment allowed, in epoch seconds (at most 900719925474).                                                                                                                      | `1893456000` (2030-01-01)        |
| `default` | no       | The moment a new record gets when the field is left out.                                                                                                                                 | `1700000000`                     |

### What the server refuses

Every write — insert, update, replace; from Cloud, the API, an SDK, the CLI or an AI agent — is checked against the published schema. A broken value is answered with one error per field: the code, and `Field '<name>' is invalid: <reason>`. Nothing is written.

| Case                                       | Code                     | The reason it gives           |
| ------------------------------------------ | ------------------------ | ----------------------------- |
| a required field is missing or `null`      | `CM-ERRORS-DATABASE-030` | `a value is required`         |
| not an integer (an ISO string, a float, …) | `CM-ERRORS-DATABASE-039` | `must be an integer`          |
| before `minimum`                           | `CM-ERRORS-DATABASE-043` | `must be at least 1700000000` |
| after `maximum`                            | `CM-ERRORS-DATABASE-043` | `must be at most 1893456000`  |

A keyword that is not in the table above is refused when the schema is **saved**, not when a record is written: `CM-ERRORS-SCHEMA-010` — `Data schema violates meta-schema: Property 'sort' has not been defined and the schema does not allow additional properties. Path 'properties.publishedOn.sort' (field 'properties.publishedOn' checked as date.schema.v1).`

Also refused at save time:

* a date field without `minimum` — it is then read as an integer field, and a `minimum` ≥ 16777216 on an integer field is refused (`CM-ERRORS-SCHEMA-010`).
* a `date.minDate` / `maxDate` that is not a relative name — `CM-ERRORS-SCHEMA-012` `String 'Someday' does not match regex pattern '^(Now|DayBefore|…)$'`; a fixed instant belongs in the data schema's `minimum` / `maximum`.

## UI schema

The cell uses `date` or `datetime`. The `date` options carry **relative** bounds that the form resolves against today; the server does not check them (it checks only the fixed `minimum` / `maximum`).

```json
{
  "colSpan": 3,
  "element": {
    "fieldId": "publishedOn",
    "meta": {
      "widget": "date",
      "label": "Published on",
      "date": { "minDate": "Now", "maxDate": "DaysAfter[30]" }
    }
  }
}
```

| Option         | What it does                                                                                                                                                                                                                                                            |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `date.minDate` | The first day the picker allows, relative to today: `Now`, `DayBefore`, `WeekBefore`, `MonthBefore`, `YearBefore`, `DayAfter`, `WeekAfter`, `MonthAfter`, `YearAfter`, or a counted form such as `DaysAfter[30]`, `WeeksBefore[2]`, `MonthsAfter[6]`, `YearsBefore[1]`. |
| `date.maxDate` | The last day the picker allows, same vocabulary.                                                                                                                                                                                                                        |

Every cell also takes the common layout options: `label`, `placeholder`, `help` (the text under the input), `required`, `readonly` and `hidden`. Keys outside this list — `watermark`, `hint`, `permissions` — are refused when the schema is saved (`CM-ERRORS-SCHEMA-012`), see [Schema authoring guide](/codemash/cloud/database/schema.md#one-contract-no-second-dialect).

<figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-bcf26f7d9372841fb5f83e4ed37825abe1941052%2Ffield-types-dates-1.png?alt=media" alt="Add New Record form of sc_e2e_all_types, Dates, flags &#x26; places tab: Boolean plain, type and default as checkboxes; Date plain, Date type, Date minimum, Date maximum and Date default as inputs with a calendar icon; Geolocation cells with Longitude and Latitude inputs"><figcaption><p>The Dates, flags &#x26; places tab: boolean, date, datetime and geo_location widgets.</p></figcaption></figure>

## Records

A record the schema accepts:

```json
{ "publishedOn": 1759795200 }
```

A record it refuses:

```json
{ "publishedOn": "2026-10-07" }
```

The answer: `CM-ERRORS-DATABASE-039` — `Field 'publishedOn' is invalid: must be an integer`. In Cloud the same sentence is shown under the field before the form is sent; the server repeats the check on every API write.

## Good to know

* Seconds, not milliseconds: `Date.now() / 1000` in JavaScript. A millisecond value is above the allowed `maximum` and is refused.
* The `date` widget writes the start of the chosen day in the viewer's time zone; `datetime` writes the chosen minute.
* A relative bound names a local day: `DaysAfter[30]` is 30 days after the day the form is opened.

## Do it from code

```ts
await norbix.api.database.insertOne({
  collectionName: 'posts',
  document: JSON.stringify({ publishedOn: Math.floor(Date.now() / 1000) }),
});
```

```sh
norbix api database one insert --collectionName posts --document '{"publishedOn":1759795200}'
```

The client setup is on the [Database page](/codemash/cloud/database.md#use-it-from-code). API: [Insert One](/codemash/api-reference/database/collections/insert-one.md) · [Save Database Schema](/codemash/api-reference/database/schemas/save-database-schema.md)

## Related

[Integer](/codemash/cloud/database/schema/field-types/integer.md) · [Boolean](/codemash/cloud/database/schema/field-types/boolean.md) · [Field type reference](/codemash/cloud/database/schema/field-types.md) · [Schema authoring guide](/codemash/cloud/database/schema.md) · [Create a schema](/codemash/cloud/database/collections/create-schema.md)
