# **TO_DATE()**

## **Function Description**

``TO_DATE()`` function converts a string to a date or date-time type according to the specified date or time display format.

A format string can contain literal characters and format specifiers starting with %. The literal characters in format must match the literal characters in str. The format specifier in format must match the date or time part in str.

## **Function Syntax**

```text
> TO_DATE(str,format)
```

## **Parameter definition**

| Arguments | Description |
| ---- | ---- |
| str | Required. <br>If ``str`` is ``NULL``, the function returns ``NULL``. <br>If the ``date`` or ``datetime`` value from ``str`` is invalid, ``TO_DATE()`` will return ``NULL`` with a warning. |
| format | Optional parameters. A format string representing the format of the return value. <br> If format is omitted, a ``DATETIME`` value is returned. <br>If format is empty, return ``NULL``. <br>If format already has the specified format, the return value is ``VARCHAR``. |

Description: The format string can contain literal characters and format specifiers starting with *%*. The literal characters in ``format`` must match the literal characters in ``str``. The format specifier in ``format`` must match the date or time part in ``str``.

## **Example**

```text
mysql> SELECT TO_DATE('2022-01-06 10:20:30','%Y-%m-%d %H:%i:%s') as result;
+--------------------------+
| result |
+--------------------------+
| 2022-01-06 10:20:30 |
+--------------------------+
1 row in set (0.00 sec)
```

## **limit**

Currently, the date format only supports the data formats of `yyyy-mm-dd` and `yyyymmdd`.
