Reputation: 1299
How do I select date and time without the seconds in mysql from a column with date value in a table ? "YYYY-MM-DD HH:MM:SS" should be "YYYY-MM-DD HH:MM"
Upvotes: 32
Views: 50600
Reputation: 272236
The proper solution is zero out seconds - and - preserve data type:
SELECT `datetime` - INTERVAL EXTRACT(SECOND FROM `datetime`) SECOND
FROM `some table`
If your datetime column contains microseconds then use this variant:
SELECT `datetime` - INTERVAL EXTRACT(SECOND_MICROSECOND FROM `datetime`) SECOND_MICROSECOND
FROM `some table`
In theory, it should be faster than examples using date formatting functions.
Upvotes: 7
Reputation: 4461
SELECT DATE_FORMAT(`date`, '%Y-%m-%d %H:%i') AS `formatted_date` FROM `table`;
Upvotes: 78