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

[Fix](doc)Sql function from_microsecond,from_millisecond,from_secon… #1947

Merged
merged 1 commit into from
Feb 6, 2025
Merged
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 @@ -23,3 +23,39 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## Description

The function converts a Unix timestamp (in microseconds) into a `DATETIME` value.


## Syntax

```sql
FROM_MICROSECOND(<unix_timestamp>)
```
## Parameters

| Parameter | Description |
|--------------------|-------------------------------------------------------------------------------------------------------------|
| `<unix_timestamp>` | Required. The Unix timestamp representing the number of microseconds elapsed since 1970-01-01 00:00:00 UTC. |

## Return Value

- Returns a DATETIME value representing the date and time corresponding to the given Unix timestamp.
- If `<unix_timestamp>` is NULL, the function returns NULL.
- If `<unix_timestamp>` is out of valid range, the function returns an error.

## Example

```sql
SELECT FROM_MICROSECOND(1700000000000000);
```

```text
+------------------------------------+
| from_microsecond(1700000000000000) |
+------------------------------------+
| 2023-11-15 06:13:20 |
+------------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,38 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## Description

The function converts a Unix timestamp (in milliseconds) into a `DATETIME` value.

## Syntax

```sql
FROM_MILLISECOND(<millisecond>)
```
## Parameters

| Parameter | Description |
|-----------------|-------------------------------------------------------------------------------------------------------------|
| `<millisecond>` | Required. The Unix timestamp representing the number of milliseconds elapsed since 1970-01-01 00:00:00 UTC. |

## Return Value

- Returns a DATETIME value representing the date and time corresponding to the given Unix timestamp.
- If <millisecond> is NULL, the function returns NULL.
- If <millisecond> is out of valid range, the function returns an error.

## Example

```sql
SELECT FROM_MILLISECOND(1700000000000);
```

```text
+---------------------------------+
| from_millisecond(1700000000000) |
+---------------------------------+
| 2023-11-15 06:13:20 |
+---------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,36 @@ specific language governing permissions and limitations
under the License.
-->

## from_second
### description
#### syntax
## Description
The function converts a Unix timestamp (in seconds) into a `DATETIME` value.

`DATETIME FROM_SECOND(BIGINT unix_timestamp)`
`DATETIME FROM_MILLISECOND(BIGINT unix_timestamp)`
`DATETIME FROM_MICROSECOND(BIGINT unix_timestamp)`

Converts a timestamp to its DATETIME represent, with argument as an integer and returned as a DATETIME type. Returns `NULL` if `unix_timestamp < 0` or if the function result is greater than `9999-12-31 23:59:59.999999`.

### example
## Syntax

```sql
FROM_SECOND(<unix_timestamp>)
```
mysql> set time_zone='Asia/Shanghai';
## Parameters

mysql> select from_second(-1);
+---------------------------+
| from_second(-1) |
+---------------------------+
| NULL |
+---------------------------+
| Parameter | Description |
|--------------------|--------------------------------------------------------------------------------------------------------|
| `<unix_timestamp>` | Required. The Unix timestamp representing the number of seconds elapsed since 1970-01-01 00:00:00 UTC. |

mysql> select from_millisecond(12345678);
+----------------------------+
| from_millisecond(12345678) |
+----------------------------+
| 1970-01-01 11:25:45.678 |
+----------------------------+
## Return Value
- Returns a DATETIME value representing the date and time corresponding to the given Unix timestamp.
- If `<unix_timestamp>` is NULL, the function returns NULL.
- If `<unix_timestamp>` is out of valid range, the function returns an error.

mysql> select from_microsecond(253402271999999999);
+--------------------------------------+
| from_microsecond(253402271999999999) |
+--------------------------------------+
| 9999-12-31 23:59:59.999999 |
+--------------------------------------+
## Example

mysql> select from_microsecond(253402272000000000);
+--------------------------------------+
| from_microsecond(253402272000000000) |
+--------------------------------------+
| NULL |
+--------------------------------------+
```sql
SELECT FROM_SECOND(1700000000);
```

### keywords

FROM_SECOND,FROM,SECOND,MILLISECOND,MICROSECOND
```text
+-------------------------+
| from_second(1700000000) |
+-------------------------+
| 2023-11-15 06:13:20 |
+-------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,38 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## Description
The function converts a `DATETIME` value into a Unix timestamp (in microseconds) starting from `1970-01-01 00:00:00 UTC`.


## Syntax

```sql
MICROSECOND_TIMESTAMP(<datetime>)
```
## Parameters

| Parameter | Description |
|--------------|---------------------------------------------------------------------|
| `<datetime>` | Required. The DATETIME value to be converted into a Unix timestamp. |

## Return Value

- Returns an integer representing the Unix timestamp (in microseconds) corresponding to the input datetime value.
- If `<datetime>` is NULL, the function returns NULL.
- If `<datetime>` is out of valid range, the function may return an error or unexpected value.

## Example

```sql
SELECT MICROSECOND_TIMESTAMP('2025-01-23 12:34:56.123456');
```

```text
+----------------------------------------------------------------------------+
| microsecond_timestamp(cast('2025-01-23 12:34:56.123456' as DATETIMEV2(6))) |
+----------------------------------------------------------------------------+
| 1737606896123456 |
+----------------------------------------------------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,38 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## Description

The `MILLISECOND_TIMESTAMP` function converts a `DATETIME` value into a Unix timestamp (in milliseconds) starting from `1970-01-01 00:00:00 UTC`.


## Syntax

```sql
MILLISECOND_TIMESTAMP(<datetime>)
```
## Parameters

| Parameter | Description |
|--------------|---------------------------------------------------------------------------------------|
| `<datetime>` | Required. The DATETIME value to be converted into a Unix timestamp (in milliseconds). |

## Return Value

- Returns an integer representing the Unix timestamp (in milliseconds) corresponding to the input datetime value.
- If `<datetime>` is NULL, the function returns NULL.
- If `<datetime>` is out of valid range, the function may return an error or unexpected value.

## Example

```sql
SELECT MILLISECOND_TIMESTAMP('2025-01-23 12:34:56');
```
```text
+---------------------------------------------------------------------+
| millisecond_timestamp(cast('2025-01-23 12:34:56' as DATETIMEV2(0))) |
+---------------------------------------------------------------------+
| 1737606896000 |
+---------------------------------------------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,38 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## Description

The function converts a `DATETIME` value into a Unix timestamp (in seconds) starting from `1970-01-01 00:00:00 UTC`.


## Syntax

```sql
SECOND_TIMESTAMP(<datetime>)
```
## Parameters

| Parameter | Description |
|--------------|---------------------------------------------------------------------|
| `<datetime>` | Required. The DATETIME value to be converted into a Unix timestamp. |

## Return Value
- Returns an integer representing the Unix timestamp (in seconds) corresponding to the input datetime value.
- If `<datetime>` is NULL, the function returns NULL.
- If `<datetime>` is out of valid range, the function may return an error or unexpected value.

## Example

```sql
SELECT SECOND_TIMESTAMP('2025-01-23 12:34:56');
```

```text
+----------------------------------------------------------------+
| second_timestamp(cast('2025-01-23 12:34:56' as DATETIMEV2(0))) |
+----------------------------------------------------------------+
| 1737606896 |
+----------------------------------------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,53 @@ specific language governing permissions and limitations
under the License.
-->

## Str_to_date
### Description
#### Syntax
## Description

`DATETIME STR_TO_DATE(VARCHAR str, VARCHAR format)`
The function converts the input datetime string into a DATETIME value based on the specified format.

Convert `str` to `DATETIME` in the manner specified by `format`. If `str` cannot be parsed in the format specified by `format`, the result is unspecified.
## Syntax

All formats in [date_format](./date-format) are supported. In addition, support auto completing the remainder of date part for '%Y' and '%Y-%m'.
```sql
STR_TO_DATE(<datetime_str>, <format>)
```
## Parameters

| Parameter | Description |
|------------------|------------------------------------------------------------------------------------------------------------------|
| `<datetime_str>` | Required. The input datetime string to be converted. |
| `<format>` | Required. The format string specifying the datetime structure, such as %Y-%m-%d %H:%i:%s or yyyy-MM-dd HH:mm:ss. |

## Return Value

- Returns a DATETIME value representing the converted datetime.
- If the input `<datetime_str>` or `<format>` is invalid, the function returns NULL.

## Example

Convert common datetime strings to DATETIME

```sql
SELECT STR_TO_DATE('2025-01-23 12:34:56', '%Y-%m-%d %H:%i:%s'),STR_TO_DATE('2025-01-23 12:34:56', 'yyyy-MM-dd HH:mm:ss');
```

```text
+---------------------------------------------------------+-----------------------------------------------------------+
| str_to_date('2025-01-23 12:34:56', '%Y-%m-%d %H:%i:%s') | str_to_date('2025-01-23 12:34:56', 'yyyy-MM-dd HH:mm:ss') |
+---------------------------------------------------------+-----------------------------------------------------------+
| 2025-01-23 12:34:56.000000 | 2025-01-23 12:34:56.000000 |
+---------------------------------------------------------+-----------------------------------------------------------+
```

### Example
Others

```sql
mysql> select str_to_date('2014-12-21 12:34:56', '%Y-%m-%d %H:%i:%s');
+---------------------------------------------------------+
| str_to_date('2014-12-21 12:34:56', '%Y-%m-%d %H:%i:%s') |
+---------------------------------------------------------+
| 2014-12-21 12:34:56 |
+---------------------------------------------------------+

mysql> select str_to_date('2014-12-21 12:34%3A56', '%Y-%m-%d %H:%i%%3A%s');
+--------------------------------------------------------------+
| str_to_date('2014-12-21 12:34%3A56', '%Y-%m-%d %H:%i%%3A%s') |
+--------------------------------------------------------------+
| 2014-12-21 12:34:56 |
+--------------------------------------------------------------+

mysql> select str_to_date('200442 Monday', '%X%V %W');
+-----------------------------------------+
| str_to_date('200442 Monday', '%X%V %W') |
+-----------------------------------------+
| 2004-10-18 |
+-----------------------------------------+

mysql> select str_to_date("2020-09-01", "%Y-%m-%d %H:%i:%s");
+------------------------------------------------+
| str_to_date('2020-09-01', '%Y-%m-%d %H:%i:%s') |
+------------------------------------------------+
| 2020-09-01 00:00:00 |
+------------------------------------------------+

mysql> select str_to_date('2023','%Y');
+---------------------------+
| str_to_date('2023', '%Y') |
+---------------------------+
| 2023-01-01 |
+---------------------------+
select STR_TO_DATE('200442 Monday', '%X%V %W'),STR_TO_DATE('2023','%Y');
```
### keywords

STR_TO_DATE,STR,TO,DATE
```text
+-----------------------------------------+---------------------------+
| str_to_date('200442 Monday', '%X%V %W') | str_to_date('2023', '%Y') |
+-----------------------------------------+---------------------------+
| 2004-10-18 | 2023-01-01 |
+-----------------------------------------+---------------------------+
```

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading