EN
MySQL - strip time from datetime column
0 points
In this article, we would like to show you how to strip time from datetime column in MySQL.
Quick solution:
xxxxxxxxxx
1
SELECT DATE(`datetime_column`)
2
FROM `table_name`;
To show how to strip time from datetime column, we will use the following table:
Note:
At the end of this article you can find database preparation SQL queries.
In this example, we will select all the datetimes from 2000-01-04
inclusive and display them without time. We will use DATE()
function so we get yyyy-mm-dd
format.
Query:
xxxxxxxxxx
1
SELECT DATE(`event_datetime`)
2
FROM `events`;
Output:
create_tables.sql
file:
xxxxxxxxxx
1
CREATE TABLE `events`(
2
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
3
`event_datetime` DATETIME,
4
PRIMARY KEY (`id`)
5
);
insert_data.sql
file:
xxxxxxxxxx
1
INSERT INTO `events`
2
(`event_datetime`)
3
VALUES
4
('2000-01-01'),
5
('2000-01-02'),
6
('2000-01-03'),
7
('2000-01-04'),
8
('2000-01-05'),
9
('2000-01-06');