Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,29 @@ specific language governing permissions and limitations
under the License.
-->

## to_date
### description
#### Syntax

`DATE TO_DATE(DATETIME)`
## Description
Date conversion function, used to convert a date time string or timestamp to a date type (DATE), that is, remove the time part and keep only the date (YYYY-MM-DD)

Return the DATE part of DATETIME value.
## Syntax
```sql
TO_DATE(<datetime_value>)
```

## Required parameter
**datetime_value**: datetime type datetime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function doc's parameter should put into a table.


### example
## Example

Convert `2020-02-02 00:00:00` to `2020-02-02`
```sql
select to_date("2020-02-02 00:00:00");
```
mysql> select to_date("2020-02-02 00:00:00");
```text
+--------------------------------+
| to_date('2020-02-02 00:00:00') |
+--------------------------------+
| 2020-02-02 |
+--------------------------------+
```

### keywords

TO_DATE
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,45 @@ specific language governing permissions and limitations
under the License.
-->

## to_days
### Description
#### Syntax

`INT TO DAYS`
## Description
Date calculation function, which is used to convert a date into a day value, that is, to calculate the total number of days from December 31, 0 AD (the base date) to the specified date.

## Syntax

Days of returning date distance 0000-01-01
```sql
TO_DAYS([<datetime_value> | <date_value>])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

简化为 TO_DAYS(<datetime_or_date_value>) 如果要强调类型,可以在参数说明中呈现

```

## Optional parameters
1. **<datetime_value>**
> datetime type datetime

2. **<date_value>**
> date type datetime

The parameter is Date or Datetime type

### example
## Example

Query how many days are there since October 7, 2007
```sql
select to_days('2007-10-07');
```
mysql> select to_days('2007-10-07');
+-----------------------+
| to_days('2007-10-07') |
+-----------------------+
| 733321 |
+-----------------------+
```text
+---------------------------------------+
| to_days(cast('2007-10-07' as DATEV2)) |
+---------------------------------------+
| 733321 |
+---------------------------------------+
```

### keywords
TO_DAYS,TO,DAYS
```sql
select to_days('2007-10-07 10:03:09');
```
```text
+------------------------------------------------+
| to_days(cast('2007-10-07 10:03:09' as DATEV2)) |
+------------------------------------------------+
| 733321 |
+------------------------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,63 @@ specific language governing permissions and limitations
under the License.
-->

## weeks_add
### description
#### Syntax
## Description
This function is used to add (or subtract) a certain number of weeks from a specified date or time value.

`DATETIME WEEKS_ADD(DATETIME date, INT weeks)`
## Syntax

ADD a specified number of weeks from a datetime or date
```sql
WEEKS_ADD([<date_value> | <datetime_value>], <weeks_value>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

类似的

```

The parameter date can be DATETIME or DATE, and the return type is consistent with that of the parameter date.
## Required parameters
**<weeks_value>**
> Integer, indicating the number of weeks to increase or decrease (positive number indicates increase, negative number indicates decrease)

### example
## Optional parameters
- **<date_value>**
> `DATE` date type input value

```
mysql> select weeks_add("2020-02-02 02:02:02", 1);
+-------------------------------------+
| weeks_add('2020-02-02 02:02:02', 1) |
+-------------------------------------+
| 2020-02-09 02:02:02 |
+-------------------------------------+
```
- **<datetime_value>**
> `DATETIME` time type input value

## example


1. Add one week to the time `2020-02-02 02:02:02`
```sql
select weeks_add("2020-02-02 02:02:02", 1);
```
```text
+-------------------------------------+
| weeks_add('2020-02-02 02:02:02', 1) |
+-------------------------------------+
| 2020-02-09 02:02:02 |
+-------------------------------------+
```

2. Subtract one week from the time `2020-02-02 02:02:02`
```sql
select weeks_add("2020-02-02 02:02:02", -1);
```
```text
+-------------------------------------------------------------+
| weeks_add(cast('2020-02-02 02:02:02' as DATETIMEV2(0)), -1) |
+-------------------------------------------------------------+
| 2020-01-26 02:02:02 |
+-------------------------------------------------------------+
```

3. Add one week to the date `2020-02-02`
```sql
select weeks_add("2020-02-02", 1);
```
```text
+--------------------------------------------+
| weeks_add(cast('2020-02-02' as DATEV2), 1) |
+--------------------------------------------+
| 2020-02-09 |
+--------------------------------------------+
```

### keywords

WEEKS_ADD
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,58 @@ specific language governing permissions and limitations
under the License.
-->

## weeks_diff
### description
#### Syntax
## Description
Calculates the number of complete weeks (in 7-day units) between two date or time values.

`INT weeks_diff(DATETIME enddate, DATETIME startdate)`
## Syntax

The difference between the start time and the end time is weeks
```sql
WEEKS_DIFF([<end_date> | <end_datetime>], [<start_date> | <start_datetime>])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WEEKS_DIFF([<end_date> | <end_datetime>], [<start_date> | <start_datetime>])
WEEKS_DIFF(<end_date> <start_date>)

```

### example
## Optional parameters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Optional parameters
## Parameters

| Parameter name | Data type | Description |
|----------------------|------------|----------------------|
| **`end_date`** | `DATE` | Later date |
| **`end_datetime`** | `DATETIME` | Later datetime |
| **`start_date`** | `DATE` | Earlier date |
| **`start_datetime`** | `DATETIME` | Earlier datetime |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在这里解释一下可以处理 date / datetime 就可以了


```
mysql> select weeks_diff('2020-12-25','2020-10-25');
+----------------------------------------------------------+
| weeks_diff('2020-12-25 00:00:00', '2020-10-25 00:00:00') |
+----------------------------------------------------------+
| 8 |
+----------------------------------------------------------+
```

### keywords
## Example

1. How many weeks are there between `2020-12-25` and `2020-10-25`
```sql
select weeks_diff('2020-12-25','2020-10-25');
```
```text
+----------------------------------------------------------+
| weeks_diff('2020-12-25 00:00:00', '2020-10-25 00:00:00') |
+----------------------------------------------------------+
| 8 |
+----------------------------------------------------------+
```

2. How many weeks are there between `2020-12-25 10:10:02` and `2020-10-25 12:10:02`
```sql
select weeks_diff('2020-12-25 10:10:02','2020-10-25 12:10:02');
```
```text
+--------------------------------------------------------------------------------------------------------+
| weeks_diff(cast('2020-12-25 10:10:02' as DATETIMEV2(0)), cast('2020-10-25 12:10:02' as DATETIMEV2(0))) |
+--------------------------------------------------------------------------------------------------------+
| 8 |
+--------------------------------------------------------------------------------------------------------+
```

weeks_diff
3. How many weeks are there between `2020-12-25 10:10:02` and `2020-10-25`
```sql
select weeks_diff('2020-12-25 10:10:02','2020-10-25');
```
```text
+----------------------------------------------------------------------------------------+
| weeks_diff(cast('2020-12-25 10:10:02' as DATETIMEV2(0)), cast('2020-10-25' as DATEV2)) |
+----------------------------------------------------------------------------------------+
| 8 |
+----------------------------------------------------------------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,47 @@ specific language governing permissions and limitations
under the License.
-->

## weeks_sub
### description
#### Syntax

`DATETIME WEEKS_SUB(DATETIME date, INT weeks)`
## Description
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缺少函数描述

## Syntax
```sql
WEEKS_SUB([<date_value> | <datetime_value>], <week_period>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WEEKS_SUB([<date_value> | <datetime_value>], <week_period>)
WEEKS_SUB(<date_value>, <week_period>)

```

Subtracts a specified number of weeks from a datetime or date
## Required parameters
**<week_period>**
> Integer representing the number of weeks to be reduced (positive number means reduction, negative number means increase).

The parameter date can be DATETIME or DATE, and the return type is consistent with that of the parameter date.
## Optional parameters
- **<date_value>**
> Date input value of type `DATE`

### example
- **<datetime_value>**
> Date and time input value of type `DATETIME`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用表格

```
mysql> select weeks_sub("2020-02-02 02:02:02", 1);
+-------------------------------------+
| weeks_sub('2020-02-02 02:02:02', 1) |
+-------------------------------------+
| 2020-01-26 02:02:02 |
+-------------------------------------+
```

### keywords
## Example

1. Subtract one week from the datetime `2020-02-02 02:02:02`
```sql
select weeks_sub("2020-02-02 02:02:02", 1);
```
```text
+-------------------------------------+
| weeks_sub('2020-02-02 02:02:02', 1) |
+-------------------------------------+
| 2020-01-26 02:02:02 |
+-------------------------------------+
```

WEEKS_SUB
2. Subtract one week from the date `2020-02-02`
```sql
select weeks_sub("2020-02-02", 1);
```
```text
+--------------------------------------------+
| weeks_sub(cast('2020-02-02' as DATEV2), 1) |
+--------------------------------------------+
| 2020-01-26 |
+--------------------------------------------+
```
Loading