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

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

`DATE TO_DATE(DATETIME)`
## Description
Date conversion function, used to convert date time (DATETIME) to 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
| Parameter | Description |
|-----------------|--------------------------|
| `datetime_value` | DATETIME type date-time |

### 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,56 @@ 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>, <start_date>)
```

### example
## Required parameters
| Parameter Name | Data Type | Description |
|---------------|----------------------|-----------------------------|
| `end_date` | `DATE`, `DATETIME` | Later date or date-time |
| `start_date` | `DATE`, `DATETIME` | Earlier date or date-time |

```
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,45 @@ 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.

缺少函数描述

Subtracts a specified number of weeks from a specified date or time value (i.e., subtracts weeks * 7 days).

Subtracts a specified number of weeks from a datetime or date
## Syntax
```sql
WEEKS_SUB(<date_value>, <week_period>)
```

The parameter date can be DATETIME or DATE, and the return type is consistent with that of the parameter date.
## Required parameters
## 必选参数
Copy link
Contributor

Choose a reason for hiding this comment

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

多余的中文标题

| Parameter | Description |
|-----------------|-----------------------------------------------------------------------------------------------------|
| `date_value` | `DATE` or `DATETIME` type input value. |
| `week_period` | Integer, representing the number of weeks to subtract (positive to decrease, negative to increase). |

### example

```
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 |
+-------------------------------------+
```
## Example

### keywords
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