# Date Truncation (DateTruncationGenerator)

The [Date Truncation](/app/generation/generators/generator-reference/date-truncation.md) generator truncates a date value or a timestamp to a specific part. For a date or a timestamp, you can truncate to the year, month, or day. For a timestamp, you can also truncate to the hour, minute, or second.

If the generator cannot process the value, then it uses the fallback generator provided in `fallbacklinks`. The available options for the fallback `generatorId` are:

* `NoFallbackGenerator` - Return an error. This is the default fallback option.
* `PassthroughGenerator`
* `ConstantGenerator`
* `NullGenerator`

## Link object structure <a href="#generator-api-date-truncation-link-object" id="generator-api-date-truncation-link-object"></a>

The Date Truncation generator does not support linking or consistency. You cannot configure differential privacy.

The `metadata` object is populated from the [`DateTruncationMetadata`](https://app.tonic.ai/apidocs/index.html#/models/DateTruncationMetadata) object. The generator-specific configuration includes the part of the datetime value to truncate to, and whether to change all dates that are more than 90 years before the generation date to a date exactly 90 years before the generation date.

```json
{
  "schema": "string",
  "table": "string",
  "column": "string",
  "path": "string",  //JSON fields only
  "dataType": "string",  //MongoDB, Amazon DynamoDB, and JSON fields only
  "metadata": {
    "presetId": "string",
    "generatorId": "DateTruncationGenerator",
    "datePart": "enum",
    "isBirthDate": boolean,
    "encryptionProcessor": "x-on", //To use configured Structural data encryption
    "customValueProcessor": "string"  //If custom value processor applied.
  }
}
```

## Example replacement <a href="#generator-api-date-truncation-replacement" id="generator-api-date-truncation-replacement"></a>

In the following example replacement for the Date Truncation generator, the values are truncated to the year. Date values that are older than 90 years before the generation date are not changed.

Values that the generator cannot process are passed through.

```json
{
  "name": "event_date",
  "schema": "public",
  "table": "events",
  "links": [
    {
      "schema": "public",
      "table": "events",
      "column": "event_date",
      "metadata": {
        "presetId": "DateTruncationGenerator",
        "generatorId": "DateTruncationGenerator",
        "datePart": "Year",
        "isBirthDate": false
      }
    }
  ],
 "fallbackLinks": [
    {
      "schema": "public",
      "table": "events",
      "column": "event_date",
      "metadata": {
        "generatorId": "PassthroughGenerator"
      }
    }
  ]
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tonic.ai/app/api/quick-start-guide/tonic-api-generator-assignment/generator-api-reference/generator-api-ref-date-truncation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
