Skip to content

DATE()

Function Description

Cut out the date part in the input in DATE or DATETIME format.

Function Syntax

> DATE(expr)

Parameter definition

Parameters Description
expr Required parameters. Input values ​​in date or datetime format need to be extracted

Example

drop table if exists t1;
create table t1(a date, b datetime);
insert into t1 values('2022-01-01','2022-01-01 01:01:01');
insert into t1 values('2022-01-01','2022-01-01 01:01:01');
insert into t1 values('20220101','2022-01-01 01:01:01');
insert into t1 values('2022-01-02','2022-01-02 23:01:01');
insert into t1 values('2021-12-31','2021-12-30 23:59:59');
insert into t1 values('2022-06-30','2021-12-30 23:59:59');

mysql> select date(a),date(b) from t1;
+-------------------------------+
| date(a) | date(b) |
+-------------------------------+
| 2022-01-01 | 2022-01-01 |
| 2022-01-01 | 2022-01-01 |
| 2022-01-01 | 2022-01-01 |
| 2022-01-02 | 2022-01-02 |
| 2021-12-31 | 2021-12-30 |
| 2022-06-30 | 2021-12-30 |
+-------------------------------+
5 rows in set (0.01 sec)

mysql> select date(a),date(date(a)) as dda from t1;
+-------------------------------+
| date(a) | dda |
+-------------------------------+
| 2022-01-01 | 2022-01-01 |
| 2022-01-01 | 2022-01-01 |
| 2022-01-01 | 2022-01-01 |
| 2022-01-02 | 2022-01-02 |
| 2021-12-31 | 2021-12-31 |
| 2022-06-30 | 2022-06-30 |
+-------------------------------+
5 rows in set (0.00 sec)

limit

Currently, the date format only supports the data formats of yyyy-mm-dd and yyyymmdd.