> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.firebolt.io/feedback

```json
{
  "path": "/reference-sql/functions-reference/date-and-time/to-yyyymmdd",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

> Reference material for the TO_YYYYMMDD function

# TO_YYYYMMDD

export const QueryWindow = ({content}) => {
  const {sql, result} = content;
  const [inited, setInited] = useState(false);
  const buttonRef = useRef(null);
  useEffect(() => {
    if (!inited && buttonRef.current) {
      runQuery(buttonRef.current, true);
      setInited(true);
    }
  }, []);
  return <div className="query-window">
      <div className="query-toolbar">
        <button className="run-button" onClick={ev => runQuery(ev.target)} ref={buttonRef}>Run Query</button>
        <span className="window-title">Interactive SQL Playground 🔥</span>
      </div>
      <div className="query-content">
        <pre><code className="firebolt-sql language-sql" contentEditable="true" spellCheck="false" data-original-query={sql}>{sql}</code></pre>
        <script type="application/json" className="fallback-result" style={{
    display: "none"
  }}>{JSON.stringify(result)}</script>
        <div className="server-unavailable-banner query-window-hidden">
          The Firebolt playground server is currently unavailable. Using precomputed query results.
        </div>
        <div className="query-results"></div>
      </div>
    </div>;
};

Extracts year, month and day from a `DATE`, `TIMESTAMP`, or `TIMESTAMPTZ` value and combines them into an integer beginning with the four-digit year followed by the two-digit month followed by the two-digit day.
`TO_YYYYMMDD(<expression>)` is equivalent to `EXTRACT(YEAR FROM <expression>) * 10000 + EXTRACT(MONTH FROM <expression>) * 100 + EXTRACT(DAY FROM <expression>);`

## Syntax

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
TO_YYYYMMDD(<expression>)
```

## Parameters

| Parameter      | Description                                             | Supported input types              |
| :------------- | :------------------------------------------------------ | :--------------------------------- |
| `<expression>` | The expression from which the time units are extracted. | `DATE`, `TIMESTAMP`, `TIMESTAMPTZ` |

`TIMESTAMPTZ` values are converted to local time according to the session's `time_zone` setting before extracting the time units.

## Return Types

`INT`

## Remarks

The `TO_YYYYMMDD` function can be used in the `PARTITION BY` clause of `CREATE TABLE` commands.

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
CREATE TABLE test (
  t TIMESTAMP
)
PARTITION BY TO_YYYYMMDD(t);
```

## Example

<QueryWindow
  content={{
"sql": "SELECT TO_YYYYMMDD('2025-04-03') as yyyymmdd, TO_YYYYMM('2025-04-03') as yyyymm;",
"result": {
"data": [
  [
    20250403,
    202504
  ]
],
"meta": [
  {
    "name": "yyyymmdd",
    "type": "int"
  },
  {
    "name": "yyyymm",
    "type": "int"
  }
],
"query": {
  "query_id": "91760611-375e-42f0-b5f5-e08a76bf307b",
  "query_label": null,
  "request_id": "1e41b5f9-74d7-4e70-abb8-bcb341bbc4b5"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.006806,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.000264784,
  "time_to_execute": 9.6012e-05
}
}
}}
/>

<QueryWindow
  content={{
"sql": "SELECT TO_YYYYMMDD('1920-12-30') as yyyymmdd, TO_YYYYMM('1920-12-30') as yyyymm;",
"result": {
"data": [
  [
    19201230,
    192012
  ]
],
"meta": [
  {
    "name": "yyyymmdd",
    "type": "int"
  },
  {
    "name": "yyyymm",
    "type": "int"
  }
],
"query": {
  "query_id": "dfce0fe1-69cd-42d5-beca-13b372631aad",
  "query_label": null,
  "request_id": "7dce31a6-a378-4a3f-9c59-67e1302c26f6"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.007533,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.000249007,
  "time_to_execute": 9.2233e-05
}
}
}}
/>
