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

# jodatime_format

> 将日期转换为指定 Joda DateTimeFormat 格式的字符串。

将某一个日期转换成指定的 Joda DateTimeFormat 格式的字符串。

## 语法

```Haskell theme={null}
VARCHAR JODATIME_FORMAT(DATETIME | DATE date, VARCHAR format)
```

## 参数说明

* `date`：待计算转换的日期，取值必须是合法的日期或日期表达式。
* `format`：计算转换后生成的日期时间的返回格式。参见 [Joda-Time format](https://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html)。

## 返回值说明

当前支持返回值为长度不超过 128 字节的字符串。如果计算转换后生成的字符串长度超过 128 字节，则返回 `NULL`。

## 示例

示例一：将日期 `2020-06-25 15:58:51` 转换为 `yyyy-MM-dd` 格式的字符串。

```SQL theme={null}
MySQL > select jodatime_format('2020-06-25 15:58:51', 'yyyy-MM-dd');
+------------------------------------------------------+
| jodatime_format('2020-06-25 15:58:51', 'yyyy-MM-dd') |
+------------------------------------------------------+
| 2020-06-25                                           |
+------------------------------------------------------+
```

示例二：将日期 `2020-06-25 15:58:51` 转换为 `yyyy-MM-dd HH:mm:ss` 格式的字符串。

```SQL theme={null}
MySQL > select jodatime_format('2020-06-25 15:58:51', 'yyyy-MM-dd HH:mm:ss');
+---------------------------------------------------------------+
| jodatime_format('2020-06-25 15:58:51', 'yyyy-MM-dd HH:mm:ss') |
+---------------------------------------------------------------+
| 2020-06-25 15:58:51                                           |
+---------------------------------------------------------------+
```

示例三：将日期 `2020-06-25 15:58:51` 转换为 `MM dd ee EE` 格式的字符串。

```SQL theme={null}
MySQL > select jodatime_format('2020-06-25 15:58:51', 'MM dd ee EE');
+-------------------------------------------------------+
| jodatime_format('2020-06-25 15:58:51', 'MM dd ee EE') |
+-------------------------------------------------------+
| 06 25 04 Thu                                          |
+-------------------------------------------------------+
```

示例四：将日期 `2020-06-25 15:58:51` 转换为 `MMM dd ee EEE` 格式的字符串。

```SQL theme={null}
MySQL > select jodatime_format('2020-06-25 15:58:51', 'MMM dd ee EEE');
+---------------------------------------------------------+
| jodatime_format('2020-06-25 15:58:51', 'MMM dd ee EEE') |
+---------------------------------------------------------+
| Jun 25 04 Thu                                           |
+---------------------------------------------------------+
```

示例五：将日期 `2020-06-25 15:58:51` 转换为 `MMMM dd ee EEEE` 格式的字符串。

```SQL theme={null}
MySQL > select jodatime_format('2020-06-25 15:58:51', 'MMMM dd ee EEEE');
+-----------------------------------------------------------+
| jodatime_format('2020-06-25 15:58:51', 'MMMM dd ee EEEE') |
+-----------------------------------------------------------+
| June 25 04 Thursday                                       |
+-----------------------------------------------------------+
```

示例六：将日期 `2023-06-25 12:00:00` 转换为 `KK:mm:ss a` 格式的字符串。

```SQL theme={null}
MySQL > select jodatime_format('2023-06-25 12:00:00', 'KK:mm:ss a');
+------------------------------------------------------+
| jodatime_format('2023-06-25 12:00:00', 'KK:mm:ss a') |
+------------------------------------------------------+
| 00:00:00 PM                                          |
+------------------------------------------------------+
```

示例七：将日期 `2023-06-25 12:00:00` 转换为 `hh:mm:ss a` 格式的字符串。

```SQL theme={null}
MySQL > select jodatime_format('2023-06-25 12:00:00', 'hh:mm:ss a');
+------------------------------------------------------+
| jodatime_format('2023-06-25 12:00:00', 'hh:mm:ss a') |
+------------------------------------------------------+
| 12:00:00 PM                                          |
+------------------------------------------------------+
```

示例八：将日期 `2023-06-25 00:00:00` 转换为 `yyyyMMdd ''starrocks''` 格式的字符串。

```SQL theme={null}
MySQL > select jodatime_format('2023-06-25 00:00:00', 'yyyyMMdd ''starrocks''');
+------------------------------------------------------------------+
| jodatime_format('2023-06-25 00:00:00', 'yyyyMMdd \'starrocks\'') |
+------------------------------------------------------------------+
| 20230625 starrocks                                               |
+------------------------------------------------------------------+
```

## 关键字

JODATIME\_FORMAT, JODA, FORMAT


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.