Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timestamp #2104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,51 @@ regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## Description

Converts a date or date-time expression to a standard date-time format.


## Syntax

```sql
TIMESTAMP(<expr>)
```

## Parameters

| Parameter | Description |
| -- | -- |
| `<expr>` | The date or date-time expression that needs to be converted |

## Return Value

Return a date-time value in the format YYYY-MM-DD HH:MM:SS.

## Examples

```sql
SELECT date '2012-08-08' + interval '2' day,
timestamp '2012-08-08 01:00' + interval '29' hour,
timestamp '2012-10-31 01:00' + interval '1' month,
date '2012-08-08' - interval '2' day,
timestamp '2012-08-08 01:00' - interval '29' hour,
timestamp '2012-10-31 01:00' - interval '1' month
```

```text
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
| days_add('2012-08-08', INTERVAL cast('2' as INT) DAY) | hours_add('2012-08-08 01:00:00', INTERVAL cast('29' as INT) HOUR) | months_add('2012-10-31 01:00:00', INTERVAL cast('1' as INT) MONTH) | days_sub('2012-08-08', INTERVAL cast('2' as INT) DAY) | hours_sub('2012-08-08 01:00:00', INTERVAL cast('29' as INT) HOUR) | months_sub('2012-10-31 01:00:00', INTERVAL cast('1' as INT) MONTH) |
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
| 2012-08-10 | 2012-08-09 06:00:00 | 2012-11-30 01:00:00 | 2012-08-06 | 2012-08-06 20:00:00 | 2012-09-30 01:00:00 |
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
{
"title": "TIMESTAMP",
"language": "zh-CN"
"title": "TIMESTAMP",
"language": "zh-CN"
}
---

Expand All @@ -13,13 +13,51 @@ regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## 描述

将日期或日期时间表达式转换为标准的日期时间格式。


## 语法

```sql
TIMESTAMP(<expr>)
```

## 参数

| 参数 | 说明 |
| -- | -- |
| `<expr>` | 需要被转换的日期或日期时间表达式 |

## 返回值

返回 `YYYY-MM-DD HH:MM:SS` 格式的日期时间值。

## 举例

```sql
SELECT date '2012-08-08' + interval '2' day,
timestamp '2012-08-08 01:00' + interval '29' hour,
timestamp '2012-10-31 01:00' + interval '1' month,
date '2012-08-08' - interval '2' day,
timestamp '2012-08-08 01:00' - interval '29' hour,
timestamp '2012-10-31 01:00' - interval '1' month
```

```text
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
| days_add('2012-08-08', INTERVAL cast('2' as INT) DAY) | hours_add('2012-08-08 01:00:00', INTERVAL cast('29' as INT) HOUR) | months_add('2012-10-31 01:00:00', INTERVAL cast('1' as INT) MONTH) | days_sub('2012-08-08', INTERVAL cast('2' as INT) DAY) | hours_sub('2012-08-08 01:00:00', INTERVAL cast('29' as INT) HOUR) | months_sub('2012-10-31 01:00:00', INTERVAL cast('1' as INT) MONTH) |
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
| 2012-08-10 | 2012-08-09 06:00:00 | 2012-11-30 01:00:00 | 2012-08-06 | 2012-08-06 20:00:00 | 2012-09-30 01:00:00 |
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,51 @@ regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## Description

Converts a date or date-time expression to a standard date-time format.


## Syntax

```sql
TIMESTAMP(<expr>)
```

## Parameters

| Parameter | Description |
| -- | -- |
| `<expr>` | The date or date-time expression that needs to be converted |

## Return Value

Return a date-time value in the format YYYY-MM-DD HH:MM:SS.

## Examples

```sql
SELECT date '2012-08-08' + interval '2' day,
timestamp '2012-08-08 01:00' + interval '29' hour,
timestamp '2012-10-31 01:00' + interval '1' month,
date '2012-08-08' - interval '2' day,
timestamp '2012-08-08 01:00' - interval '29' hour,
timestamp '2012-10-31 01:00' - interval '1' month
```

```text
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
| days_add('2012-08-08', INTERVAL cast('2' as INT) DAY) | hours_add('2012-08-08 01:00:00', INTERVAL cast('29' as INT) HOUR) | months_add('2012-10-31 01:00:00', INTERVAL cast('1' as INT) MONTH) | days_sub('2012-08-08', INTERVAL cast('2' as INT) DAY) | hours_sub('2012-08-08 01:00:00', INTERVAL cast('29' as INT) HOUR) | months_sub('2012-10-31 01:00:00', INTERVAL cast('1' as INT) MONTH) |
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
| 2012-08-10 | 2012-08-09 06:00:00 | 2012-11-30 01:00:00 | 2012-08-06 | 2012-08-06 20:00:00 | 2012-09-30 01:00:00 |
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,51 @@ regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## 描述

将日期或日期时间表达式转换为标准的日期时间格式。


## 语法

```sql
TIMESTAMP(<expr>)
```

## 参数

| 参数 | 说明 |
| -- | -- |
| `<expr>` | 需要被转换的日期或日期时间表达式 |

## 返回值

返回 `YYYY-MM-DD HH:MM:SS` 格式的日期时间值。

## 举例

```sql
SELECT date '2012-08-08' + interval '2' day,
timestamp '2012-08-08 01:00' + interval '29' hour,
timestamp '2012-10-31 01:00' + interval '1' month,
date '2012-08-08' - interval '2' day,
timestamp '2012-08-08 01:00' - interval '29' hour,
timestamp '2012-10-31 01:00' - interval '1' month
```

```text
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
| days_add('2012-08-08', INTERVAL cast('2' as INT) DAY) | hours_add('2012-08-08 01:00:00', INTERVAL cast('29' as INT) HOUR) | months_add('2012-10-31 01:00:00', INTERVAL cast('1' as INT) MONTH) | days_sub('2012-08-08', INTERVAL cast('2' as INT) DAY) | hours_sub('2012-08-08 01:00:00', INTERVAL cast('29' as INT) HOUR) | months_sub('2012-10-31 01:00:00', INTERVAL cast('1' as INT) MONTH) |
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
| 2012-08-10 | 2012-08-09 06:00:00 | 2012-11-30 01:00:00 | 2012-08-06 | 2012-08-06 20:00:00 | 2012-09-30 01:00:00 |
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,51 @@ regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## Description

Converts a date or date-time expression to a standard date-time format.


## Syntax

```sql
TIMESTAMP(<expr>)
```

## Parameters

| Parameter | Description |
| -- | -- |
| `<expr>` | The date or date-time expression that needs to be converted |

## Return Value

Return a date-time value in the format YYYY-MM-DD HH:MM:SS.

## Examples

```sql
SELECT date '2012-08-08' + interval '2' day,
timestamp '2012-08-08 01:00' + interval '29' hour,
timestamp '2012-10-31 01:00' + interval '1' month,
date '2012-08-08' - interval '2' day,
timestamp '2012-08-08 01:00' - interval '29' hour,
timestamp '2012-10-31 01:00' - interval '1' month
```

```text
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
| days_add('2012-08-08', INTERVAL cast('2' as INT) DAY) | hours_add('2012-08-08 01:00:00', INTERVAL cast('29' as INT) HOUR) | months_add('2012-10-31 01:00:00', INTERVAL cast('1' as INT) MONTH) | days_sub('2012-08-08', INTERVAL cast('2' as INT) DAY) | hours_sub('2012-08-08 01:00:00', INTERVAL cast('29' as INT) HOUR) | months_sub('2012-10-31 01:00:00', INTERVAL cast('1' as INT) MONTH) |
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
| 2012-08-10 | 2012-08-09 06:00:00 | 2012-11-30 01:00:00 | 2012-08-06 | 2012-08-06 20:00:00 | 2012-09-30 01:00:00 |
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,51 @@ regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## 描述

将日期或日期时间表达式转换为标准的日期时间格式。


## 语法

```sql
TIMESTAMP(<expr>)
```

## 参数

| 参数 | 说明 |
| -- | -- |
| `<expr>` | 需要被转换的日期或日期时间表达式 |

## 返回值

返回 `YYYY-MM-DD HH:MM:SS` 格式的日期时间值。

## 举例

```sql
SELECT date '2012-08-08' + interval '2' day,
timestamp '2012-08-08 01:00' + interval '29' hour,
timestamp '2012-10-31 01:00' + interval '1' month,
date '2012-08-08' - interval '2' day,
timestamp '2012-08-08 01:00' - interval '29' hour,
timestamp '2012-10-31 01:00' - interval '1' month
```

```text
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
| days_add('2012-08-08', INTERVAL cast('2' as INT) DAY) | hours_add('2012-08-08 01:00:00', INTERVAL cast('29' as INT) HOUR) | months_add('2012-10-31 01:00:00', INTERVAL cast('1' as INT) MONTH) | days_sub('2012-08-08', INTERVAL cast('2' as INT) DAY) | hours_sub('2012-08-08 01:00:00', INTERVAL cast('29' as INT) HOUR) | months_sub('2012-10-31 01:00:00', INTERVAL cast('1' as INT) MONTH) |
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
| 2012-08-10 | 2012-08-09 06:00:00 | 2012-11-30 01:00:00 | 2012-08-06 | 2012-08-06 20:00:00 | 2012-09-30 01:00:00 |
+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+--------------------------------------------------------------------+
```