> ## 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.

> Reference material for the TO_YYYYMM function

# TO_YYYYMM

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 the year and month 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.
`TO_YYYYMM(<expression>)` is equivalent to `EXTRACT(YEAR FROM <expression>) * 100 + EXTRACT(MONTH FROM <expression>);`

## Syntax

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
TO_YYYYMM(<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_YYYYMM` 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_YYYYMM(t);
```

## Example

<QueryWindow
  content={{
"sql": "SELECT TO_YYYYMM('2025-04-03') as yyyymm, TO_YYYYMMDD('2025-04-03') as yyyymmdd;",
"result": {
"data": [
  [
    202504,
    20250403
  ]
],
"meta": [
  {
    "name": "yyyymm",
    "type": "int"
  },
  {
    "name": "yyyymmdd",
    "type": "int"
  }
],
"query": {
  "query_id": "a1cb2c13-a57b-4fc5-86c3-feaf158f374d",
  "query_label": null,
  "request_id": "2eb57b08-0ca7-43d7-a248-602ef215db50"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.006679,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.000249803,
  "time_to_execute": 8.9646e-05
}
}
}}
/>

<QueryWindow
  content={{
"sql": "SELECT TO_YYYYMM('1920-12-30') as yyyymm, TO_YYYYMMDD('1920-12-30') as yyyymmdd;",
"result": {
"data": [
  [
    192012,
    19201230
  ]
],
"meta": [
  {
    "name": "yyyymm",
    "type": "int"
  },
  {
    "name": "yyyymmdd",
    "type": "int"
  }
],
"query": {
  "query_id": "03d8e156-be4b-4240-93b9-0232a45bf551",
  "query_label": null,
  "request_id": "ddf9a494-f656-4621-a6d9-c9cb5fa3af66"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.009652,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.000258842,
  "time_to_execute": 9.1961e-05
}
}
}}
/>
